q
参数上使用的query_string查询首先通过在空格上分割查询字符串来解析查询字符串。您需要用其他保留空间的东西替换它。在这里match
查询将是一个不错的选择。我还将使用其他分析器进行搜索- 您无需在其中应用ngram:
curl -XPUT http://localhost:9200/autocomplete/ -d '
{
"index": {
"analysis": {
"analyzer": {
"placeNameIndexAnalyzer" : {
"type": "custom",
"tokenizer": "keyword",
"filter" : ["trim", "lowercase", "asciifolding", "left_ngram"]
},
"placeNameSearchAnalyzer" : {
"type": "custom",
"tokenizer": "keyword",
"filter" : ["trim", "lowercase", "asciifolding"]
}
},
"filter": {
"left_ngram": {
"type" : "edgeNGram",
"side" : "front",
"min_gram" : 3,
"max_gram" : 12
}
}
}
}
}'
curl -XPUT http://localhost:9200/autocomplete/geo/_mapping/ -d '
{
"geo": {
"properties": {
"application_id": {
"type": "string"
},
"alias": {
"type": "string",
"index_analyzer": "placeNameIndexAnalyzer",
"search_analyzer": "placeNameSearchAnalyzer"
},
"name": {
"type": "string"
},
"object_type": {
"type": "string"
}
}
}
}'
curl -XPOST "http://localhost:9200/autocomplete/geo?refresh=true" -d '
{
"application_id":"982",
"name":"Buenos Aires",
"alias":["bue", "buenos aires", "bsas", "bs as", "baires"],
"object_type":"cities"
}'
curl -XGET 'localhost:9200/autocomplete/geo/_search' -d '{
"query": {
"match": {
"alias": "bs as"
}
}
}'