【问题标题】:Elasticsearch match with filterElasticsearch 匹配过滤器
【发布时间】:2017-05-27 14:53:44
【问题描述】:

我需要一个对字符串进行部分匹配的查询,并过滤具有特定字段值的外部文档。

我为 es 尝试了这个有效载荷:

    payload = {
    search_request: {
      _source: [ 'name', 'source','pg_id' ],
      query: {
        match: { name: query_string }
        bool: {
          must_not: {
            term: { "source.source": source_value }
          }
        }
      },
      size: 100
    },
    query_hint: query,
    algorithm: algorithm,
    field_mapping: { title: ["_source.name", "_source.source"]}
  }

但是 ES 抛出这个错误:

    {  
:error=>   {  
:root_cause=>      [  
         {  
:type=>"parse_exception",
:reason=> 
           "failed to parse search source. expected field name but got            [  
               START_OBJECT
            ]            "}], 
       :type=>"            search_phase_execution_exception",
:reason=>"all shards failed",
:phase=>"query",
:grouped=>true,
:failed_shards=>            [  
               {  
:shard=>0,
:index=>"articles",
:node=>"3BUP3eN_TB2-zExigd_k2g",
:reason=>                  {  
:type=>"parse_exception",
:reason=> 
             "failed to parse search source. expected field name but got                     [  
                        START_OBJECT
                     ]                     "
                  }
               }
            ]
         },
:status=>400
      }

我正在使用 Elasticsearch 2.4

【问题讨论】:

    标签: elasticsearch elasticsearch-2.0


    【解决方案1】:

    首先,您的 json 格式无效。检查逗号和引号。 此外,如果您只需要过滤文档 - 过滤器比查询快得多。检查documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      • 2020-08-27
      相关资源
      最近更新 更多