我将此gem用于elasticsearch API 我试图将以下curl语句转换为等效的API调用
curl -X GET 'localhost:9200/_search?pretty=true' -d '{
"size": 100,
"fields": [
"@message",
"@timestamp"
],
"query": {
"term": {
"@message": "drop"
}
}
}'
我尝试了这些但没有得到预期的结果
Elasticsearch API
@esearch = Elasticsearch::Client.new log: true
@data2 = @esearch.search q: {
term:{
"@message" => "drop"
}
},
size:'100',
fields:'["@message", "@timestamp"]'
传输API
client = Elasticsearch::Client.new
@data = client.perform_request 'GET', '_search', {
:size=> 100,
:query=> {
:term=> {
"message"=> "drop"
}
},
{
:fields=> [
'@message',
'@timestamp'
]
}
}
请帮忙
答案 0 :(得分:1)
您需要将所有这些参数包装在body
元素中:
@data2 = @esearch.search
body: {
query: {term:{"@message" => "drop"}},
size:'100',
fields:'["@message", "@timestamp"]
}