2015-08-08 59 views
1

我能夠爲以下彈性的搜索查詢得到的數據:彈性搜索:匹配查詢沒有嵌套布爾工作濾清器

{ 
    "query": { 
    "filtered": { 
     "query": [], 
     "filter": { 
     "bool": { 
      "must": [ 
      { 
       "bool": { 
       "should": [ 
        { 
        "term": { 
         "gender": "malE" 
        } 
        }, 
        { 
        "term": { 
         "sentiment": "positive" 
        } 
        } 
       ] 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

但是,如果我查詢中使用「匹配」 - 我得到400錯誤信息狀態響應

{ 
    "query": { 
    "filtered": { 
     "query": [], 
     "filter": { 
     "bool": { 
      "must": [ 
      { 
       "bool": { 
       "should": [ 
        { 
        "match": { 
         "gender": "malE" 
        } 
        }, 
        { 
        "term": { 
         "sentiment": "positive" 
        } 
        } 
       ] 
       } 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

匹配查詢在嵌套bool過濾器中不受支持嗎?

由於術語查詢在字段的倒排索引中查找確切的術語,我想查詢性別數據作爲case_insensitive字段 - 我應該嘗試哪種方法?

{ 
    "settings": { 
    "index": { 
     "analysis": { 
     "analyzer": { 
      "analyzer_keyword": { 
      "tokenizer": "keyword", 
      "filter": "lowercase" 
      } 
     } 
     } 
    } 
    } 
} 

的映射場性別:指數

設置

{"type":"string","analyzer":"analyzer_keyword"} 
+0

更容易 –

+0

@johnSmith我沒有得到你。你的意思是我應該搜索使屬性小寫,然後通過術語查詢進行搜索? –

+0

我的意思是你最有可能的索引對象,並有一個elasticsearch的映射,你可以簡單地添加一個屬性和一個getter函數到你的對象類,返回小寫的名字,將這個字段添加到彈性映射,你沒有問題 –

回答

1

原因你得到一個錯誤400是因爲沒有match過濾器,只match queries,即使有term queriesterm filters

你的查詢可以是這樣簡單,即不需要一個filtered查詢,只需把你的termmatch查詢到bool/should

{ 
    "query": { 
    "bool": { 
     "should": [ 
     { 
      "match": { 
      "gender": "male" 
      } 
     }, 
     { 
      "term": { 
      "sentiment": "positive" 
      } 
     } 
     ] 
    } 
    } 
} 
如果你花太多的時間,索引一個小寫的屬性可能
+0

謝謝。我雖然匹配將在過濾器dsl中工作,因爲我使用的是/無輸出。除上述以外,我應該使用哪種方法進行不區分大小寫的搜索 - 例如「情感」字段中的「非常積極」的集合。 提交的情緒包含 [「積極」,「非常積極」,「消極」,「非常消極」] –