elasticsearch-railsを使ってelasticsearchとやりとりするときに、詳細な通信ログを見る方法。
log: true, trace: true
をオプションで渡せばOK
Elasticsearch::Client.new(hosts: 'localhost:9999', log: true, trace: true)
リクエストとレスポンスのJSONと、curlコマンドまで出してくれる。
2023-06-23 00:00:00 +0900: > {"query":{"bool":{"filter":[{"terms":{"id":[999]}}]}},"sort":{"id":"desc"},"size":100,"from":0,"track_total_hits":true,"_source":["id"]}
2023-06-23 00:00:00 +0900: < {"took":6,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":0,"relation":"eq"},"max_score":null,"hits":[]}}
curl -X POST -H 'x-elastic-client-meta: es=7.13.3,rb=2.7.0,t=7.13.3,fd=1.10.2,hc=2.8.3, User-Agent: elasticsearch-ruby/7.13.3 (RUBY_VERSION: 2.7.0; linux aarch64; Faraday v1.10.2), Content-Type: application/json' 'http://localhost:9999/applications/_search?pretty' -d '{
"query": {
"bool": {
"filter": [
{
"terms": {
"id": [
999
]
}
}
]
}
},
"sort": {
"id": "desc"
},
"size": 100,
"from": 0,
"track_total_hits": true,
"_source": [
"id"
]
}'