2017-05-27 156 views
-1

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

我想这有效载荷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 trows此错误:

{ 
: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

回答

0

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