2017-10-12 145 views
0

我在名稱上搜索某些名稱中含有特殊字符的名稱(&,(),')。 我的索引映射這個樣子的搜索名稱和彈性搜索中的特殊字符

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

    "mappings": { 
     "doc": { 
      "properties": { 
       "namefeild": { 
        "search_analyzer": "analyzer_startswith", 
        "analyzer": "analyzer_startswith", 
        "type": "string" 
       } 
      } 
     } 
    } 

我想搜索的名字「你&我」。

{"query":{"bool":{"must":[{"match_phrase_prefix":{"namefeild":"you & me"}}}]}},"from":0,"size":100} 

這裏當我搜索的名字,直到「你&」我得到結果後,我,我得到的結果無效。 請幫幫我。

回答

0

工作正常,我對「你&」和「你&我」

如果這還不能爲你工作,請發表其返回null結果

PUT sf 
{ 
    "settings": { 
     "index": { 
      "analysis": { 
       "analyzer": { 
        "analyzer_startswith": { 
         "tokenizer": "keyword", 
         "filter": "lowercase" 
        } 
       } 
      } 
     } 
    }, 

    "mappings": { 
     "doc": { 
      "properties": { 
       "namefeild": { 
        "search_analyzer": "analyzer_startswith", 
        "analyzer": "analyzer_startswith", 
        "type": "string" 
       } 
      } 
     } 
    } 

} 


POST sf/_analyze 
{ 
    "analyzer": "analyzer_startswith", 
    "text":  "you &" 
} 


POST _bulk 
{ "index" : { "_index" : "sf", "_type" : "doc", "_id" : "1" } } 
{"namefeild": "you" } 
{ "index" : { "_index" : "sf", "_type" : "doc", "_id" : "2" } } 
{"namefeild": "you & me" } 


GET sf/_search 
{ 
    "query": { 
     "bool": { 
      "must": [{ 
       "match_phrase_prefix": { 
        "namefeild": "you & me" 
       } 
      } 
     ]} 
    } 
+0

不工作的確切查詢我 – maddy

+0

請提供您正在使用的確切的一組命令?你的ES版本是什麼? – user2297083