2017-03-03 48 views
2

一句,我有以下字符串:ElasticSearch 5.2分與空格

"hello world" 
"hello" 
"hello world all" 

和我的映射看起來像這樣

... 
"properties": { 
    "my_field": { 
    "type": "string", 
    "index": "not_analyzed" 
    } 
} 
... 

當我嘗試使用simple_query_string執行搜索:

{ 
    "query": { 
    "simple_query_string" : { 
     "query": "hello" 
    } 
    } 
} 

我得到所有三個字符串。

問題是我只需要一個與「你好」相關的字符串。

回答

0

使用term query得到一個精確匹配

{ 
    "query": { 
    "term" : { 
     "my_field": "hello" 
    } 
    } 
} 

注意,在ES 5,您可以通過指定keyword

"properties": { 
    "my_field": { 
    "type": "keyword" 
    } 
} 
簡化你的映射