Elastic search 带空格的术语
我在为elasticsearch实现自动完成功能时遇到问题,这是我的
设置:
创建自动完成的分析器
curl -XPUT http://localhost:9200/autocomplete/ -d '{
"index": {
"analysis": {
"analyzer": {
"placeNameIndexAnalyzer": {
"type": "custom",
"tokenizer": "keyword",
"filter": [
"trim",
"lowercase",
"asciifolding",
"left_ngram"
]
}
},
"filter": {
"left_ngram": {
"type": "edgeNGram",
"side": "front",
"min_gram": 3,
"max_gram": 12
}
}
}
}
}'
然后,使用“ alias”
属性中的分析器在自动完成中创建一个类型:
curl -XPUT http://localhost:9200/autocomplete/geo/_mapping/ -d '{
"geo": {
"properties": {
"application_id": {
"type": "string"
},
"alias": {
"type": "string",
"analyzer": "placeNameIndexAnalyzer"
},
"name": {
"type": "string"
},
"object_type": {
"type": "string"
}
}
}
}'
Afterwards; add a document:
curl -XPOST http://localhost:9200/autocomplete/geo -d '{
"application_id": "982",
"name": "Buenos Aires",
"alias": [
"bue",
"buenos aires",
"bsas",
"bs as",
"baires"
],
"object_type": "cities"
}'
When I run the following:
curl -XGET 'localhost:9200/autocomplete/geo/_search?q=alias:bs%20as'
result is
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
and
curl -XGET 'localhost:9200/autocomplete/geo/_search?q=alias:bs as'
curl: (52) Empty reply from server
But I should be getting my document for in the “alias” field I have a “bs as”.
I tried using the _analyze
API and I get what I think is the correct answer
with the expected tokens:
curl -XGET 'localhost:9200/autocomplete/_analyze?analyzer=placeNameIndexAnalyzer' -d 'bs as'
result:
{
"tokens": [
{
"token": "bs ",
"start_offset": 0,
"end_offset": 5,
"type": "word",
"position": 1
},
{
"token": "bs a",
"start_offset": 0,
"end_offset": 5,
"type": "word",
"position": 1
},
{
"token": "bs as",
"start_offset": 0,
"end_offset": 5,
"type": "word",
"position": 1
}
]
}
Any Hints?
EDIT: when I run analyze with the actual type I get this:
curl -XGET 'localhost:9200/autocomplete/_analyze?analyzer=placeNameIndexAnalyzer' -d 'bs as'
result:
{
"_index": "autocomplete",
"_type": "geo",
"_id": "_analyze",
"exists": false
}
-
参数上使用的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" } } }'
-
Elastic Search中嵌套字段的术语聚合
2021-02-01 关注 0 浏览93 1答案
-
使用C#在其中具有空格和特殊字符的Elastic Search-Search字符串
2021-02-01 关注 0 浏览160 1答案
-
elasticsearch带空格的术语
2021-02-01 关注 0 浏览100 1答案
-
使用Elastic Search检索标签内容和带连字符的单词
2021-02-01 关注 0 浏览229 1答案
-
Elastic search-search_after参数
2021-02-01 关注 0 浏览251 1答案
-
云中的Elastic search集群
2021-02-01 关注 0 浏览154 1答案
-
Elastic search-search_analyzer与index_analyzer
2021-02-01 关注 0 浏览235 1答案
-
Elastic search限制结果
2021-02-01 关注 0 浏览189 1答案
-
Elastic Search嵌套对象查询
2021-02-01 关注 0 浏览122 1答案
-
Elastic search和Codeigniter(PHP)
2021-02-01 关注 0 浏览139 1答案