Reputation: 1305
Could you help me with ElasticSearch suggesting: 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 'Content-Type: application/json' -d'
{
"company": {
"properties": {
"id": {
"type": "integer"
},
"inn": {
"type": "keyword"
},
"innSuggest" : {
"type" : "completion"
}
}
}
}
'
Filled it with some amount of data
curl -XGET 'http://localhost:9200/tass_suggest_test/company/_search?pretty' -d'
{
"from" : 0, "size" : 1,
"query" : {
"wildcard" : { "inn" : "78200*" }
}
}'
It's ok, I got some data:
{
"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"
}
}
]
}
}
But when I'm trying suggest query I got nothing
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" : [ ]
}
]
}
Where is my fault?
Upvotes: 2
Views: 703
Reputation: 897
The completion suggester uses the simple analyzer by default, so numbers were removed from the input field. If you want to preserve numbers you could use the whitespace analyzer of your suggest field:
{
"company": {
"properties": {
"id": {
"type": "integer"
},
"inn": {
"type": "keyword"
},
"innSuggest" : {
"type" : "completion",
"analyzer": "whitespace"
}
}
}
}
Upvotes: 1