php - 在搜索数据时出现 Elasticsearch 错误请求

标签 php elasticsearch

我在json下面将数据搜索到 Elasticsearch 数组中,但我总是得到异常而不是下面的搜索响应,这是异常并搜索我要用户搜索的json数据

 {
        "index":"people",
        "type":"people_list",
        "from":0,
        "size":"20",
        "body":{
          "query":{
              "bool":{
                  "must_not":{
                      "terms":{"id":"2"}
                   },
                  "must":{
                      "terms":{"is_live":1}
                  }
               }
            }
        }
   }

异常(exception)
<pre>{"error":"SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[QPbfeXzKTpOjM53S5Y09ng][people][0]: SearchParseException[[people][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must_not\":{\"terms\":{\"id\":\"2\"}},\"must\":{\"terms\":{\"is_live\":1}}}}}]]]; nested: QueryParsingException[[people] [terms] query does not support [id]]; }{[QPbfeXzKTpOjM53S5Y09ng][people][1]: SearchParseException[[people][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must_not\":{\"terms\":{\"id\":\"2\"}},\"must\":{\"terms\":{\"is_live\":1}}}}}]]]; nested: QueryParsingException[[people] [terms] query does not support [id]]; }{[QPbfeXzKTpOjM53S5Y09ng][people][2]: SearchParseException[[people][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must_not\":{\"terms\":{\"id\":\"2\"}},\"must\":{\"terms\":{\"is_live\":1}}}}}]]]; nested: QueryParsingException[[people] [terms] query does not support [id]]; }{[QPbfeXzKTpOjM53S5Y09ng][people][3]: SearchParseException[[people][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must_not\":{\"terms\":{\"id\":\"2\"}},\"must\":{\"terms\":{\"is_live\":1}}}}}]]]; nested: QueryParsingException[[people] [terms] query does not support [id]]; }{[QPbfeXzKTpOjM53S5Y09ng][people][4]: SearchParseException[[people][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must_not\":{\"terms\":{\"id\":\"2\"}},\"must\":{\"terms\":{\"is_live\":1}}}}}]]]; nested: QueryParsingException[[people] [terms] query does not support [id]]; }]","status":400}

flex 搜寻版本
{
  "status" : 200,
  "name" : "Data",
  "cluster_name" : "ElasticSearch",
  "version" : {
    "number" : "1.7.2",
    "build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
    "build_timestamp" : "2015-09-14T09:49:53Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}

最佳答案

如果要使用terms,则该值应为数组。

您有2个选择:

  • terms更改为term
    {"term": { "id":"2" }}
    
  • terms的值更改为如下数组:
    {"terms":{"id":["2"]}}
    
  • 关于php - 在搜索数据时出现 Elasticsearch 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47531080/

    相关文章:

    php - Windows PHP 上的 PostgreSQL 问题

    http - Docker容器http请求限制

    elasticsearch - Elasticsearch dis_max查询,返回完全匹配的查询

    php - 无法连接MySQL数据库

    javascript - 将 JS 日期对象发送到 PHP

    php - 连接三张表-mysql

    elasticsearch - elasticsearch中copy_to和analys之间的奇怪交互

    php - PDO 出现错误

    configuration - 创建单独的master+data和client+data的elasticsearch节点

    amazon-web-services - 连接到Elasticsearch-Amazon Elasticsearch Service-IAM用户