2016-02-13 95 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" 
      } 
     } 
     ] 
    } 
    } 
} 

希望這將幫助你和點你在正確的道路:)

問候, 丹尼爾