2016-02-13 58 views
2

这是我的查询elasticsearch如何包括在比赛短语相同领域的许多价值观

GET blablabla/_search 
{ 
    "query": { 
    "bool": { 
     "must": [ 
     {"match" : {"source" : "balblabla"}}, 
     {"match" :{"blablablab" : "JBR"}}, 
     {"match": {"city" : "blab bla"}}, 
     {"match" : {"something": ["Balcony" , "Gym"]}} 
     ] 
    } 
    } 
} 

我收到此错误:

{ 
    "error": { 
     "root_cause": [ 
     { 
      "type": "query_parsing_exception", 
      "reason": "[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?", 
      "index": "index name goes here", 
      "line": 8, 
      "col": 35 
     } 
     ], 
     "type": "search_phase_execution_exception", 
     "reason": "all shards failed", 
     "phase": "query", 
     "grouped": true, 
     "failed_shards": [ 
     { 
      "shard": 0, 
      "index": "index name goes here", 
      "node": "4Qjq5UGPSZO2Qtg-ECI_mQ", 
      "reason": { 
       "type": "query_parsing_exception", 
       "reason": "[match] query parsed in simplified form, with direct field name, but included more options than just the field name, possibly use its 'options' form, with 'query' element?", 
       "index": "index name goes here", 
       "line": 8, 
       "col": 35 
      } 
     } 
     ] 
    }, 
    "status": 400 
} 

当我删除此行

{"match" : {"something": ["Balcony" , "Gym"]}}

它工作正常,但为什么该行导致解析错误,s ince数组在json中很好吗?

我elasticsearch版本是2.2

回答

4

这个错误来自解析器,你必须用“OR”路过的时候多针指定。

解决您的情况下,你必须更换

{ 
    "match": { 
    "something": [ 
     "Balcony", 
     "Gym" 
    ] 
    } 
} 

{ 
    "match": { 
    "something": "Balcony OR Gym" 
    } 
} 

所以在最后就应该是这样的:

{ 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "match": { 
      "source": "balblabla" 
      } 
     }, 
     { 
      "match": { 
      "blablablab": "JBR" 
      } 
     }, 
     { 
      "match": { 
      "city": "blab bla" 
      } 
     }, 
     { 
      "match": { 
      "something": "Balcony OR Gym" 
      } 
     } 
     ] 
    } 
    } 
} 

希望这将帮助你和点你在正确的道路:)

问候, 丹尼尔