根据 ES 文档,这两个搜索请求应该得到相同的结果:
获取
http://localhost:9200/app/users/_search?source={"query": {"term": {"email":"foo@gmail.com"}}}
发布
http://localhost:9200/app/users/_search
帖子正文:
{
"query": {
"term": {
"email":"foo@gmail.com"
}
}
}
但是第一个没有给出结果,而第二个给出了预期的结果。我使用 ES 版本 0.19.10 其他人有同样的行为吗?这是错误吗?
最佳答案
根据 URI Search,
source
不是有效的查询字符串参数
Elasticsearch 允许三种方式来执行搜索请求...
GET 请求正文:
curl -XGET "http://localhost:9200/app/users/_search" -d '{
"query": {
"term": {
"email": "foo@gmail.com"
}
}
}'
带有请求正文的 POST:
Since not all clients support GET with body, POST is allowed as well.
curl -XPOST "http://localhost:9200/app/users/_search" -d '{
"query": {
"term": {
"email": "foo@gmail.com"
}
}
}'
没有请求正文的 GET:
curl -XGET "http://localhost:9200/app/users/_search?q=email:foo@gmail.com"
或者(如果您想手动对查询字符串进行 URL 编码)
curl -XGET "http://localhost:9200/app/users/_search?q=email%3Afoo%40gmail.com"
关于search - ElasticSearch POST with json search body vs GET with json in url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14339696/