你能否帮我解决ElasticSearch建议: https://www.elastic.co/guide/en/elasticsearch/reference/5.1/search-suggesters-completion.html
curl -XPUT' localhost:9200 / tass_suggest_test / _mapping / company?pretty' -H'内容类型:application / json' -d'
{
"company": {
"properties": {
"id": {
"type": "integer"
},
"inn": {
"type": "keyword"
},
"innSuggest" : {
"type" : "completion"
}
}
}
}
'
用一些数据填充
curl -XGET' http://localhost:9200/tass_suggest_test/company/_search?pretty' -d'
{
"from" : 0, "size" : 1,
"query" : {
"wildcard" : { "inn" : "78200*" }
}
}'
没关系,我得到了一些数据:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 10,
"successful" : 10,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 1.0,
"hits" : [
{
"_index" : "tass_suggest_test",
"_type" : "company",
"_id" : "23515589",
"_score" : 1.0,
"_source" : {
"id" : 23515589,
"inn" : "7820056885",
"innSuggest" : "7820056885"
}
}
]
}
}
但是,当我尝试建议查询时,我什么都没得到
curl -XGET 'localhost:9200/tass_suggest_test/_suggest?pretty' -H 'Content-Type: application/json' -d'
{
"company-suggest" : {
"prefix" : "78200",
"completion" : {
"field" : "innSuggest"
}
}
}
'
{
"_shards" : {
"total" : 10,
"successful" : 10,
"failed" : 0
},
"company-suggest" : [
{
"text" : "7820056885",
"offset" : 0,
"length" : 10,
"options" : [ ]
}
]
}
我的错在哪里?
答案 0 :(得分:1)
默认情况下,完成建议器使用简单分析器,因此从输入字段中删除了数字。如果您想保留数字,可以使用建议字段的空白分析器:
{
"company": {
"properties": {
"id": {
"type": "integer"
},
"inn": {
"type": "keyword"
},
"innSuggest" : {
"type" : "completion",
"analyzer": "whitespace"
}
}
}
}