2017-10-12 147 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