search - ElasticSearch POST with json search body vs GET with json in url

标签 search post elasticsearch get

根据 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/

相关文章:

php - 阻止通过 PHP 进行远程访问

filter - 将聚合限制为过滤器的结果

excel - MS Excel 在搜索功能中通过测距

reactjs - 如何在 URL axios post 方法中使用 id 使用react?

javascript - Express - 如何从 POST 表单获取数据

search - Solr 与 ElasticSearch

elasticsearch - 具有多个条件和时间范围的Elasticsearch查询

mysql - 通过连接表搜索仅显示来自一个表的匹配数据

android - 如何从谷歌地方检索搜索建议?

html - 为什么当我在搜索栏中按 Enter 键时看不到查询参数?