Elasticsearch与过滤器匹配

时间:2017-05-27 14:53:45

标签: elasticsearch elasticsearch-2.0

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

我为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

1 个答案:

答案 0 :(得分:0)

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