Seems, I have an issue with sorting the results. Below is my config:
curl -X PUT localhost:9200/companies -d '
{
"settings" : {
"analysis" : {
"char_filter": {
"punctuation_removal": {
"type": "pattern_replace",
"pattern": "[\.,/]",
"replacement": " "
}
},
"analyzer" : {
"my_edge_ngram_analyzer" : {
"char_filter" :["punctuation_removal"],
"tokenizer" : "my_edge_ngram_tokenizer",
"filter" : ["standard", "lowercase"]
}
},
"tokenizer" : {
"my_edge_ngram_tokenizer" : {
"type" : "edgeNGram",
"min_gram" : "1",
"max_gram" : "5",
"token_chars": [ "letter", "digit" ]
}
}
}
},
"mappings": {
"company" : {
"properties" : {
"name" : { "type" : "string" },
"count" : {"type": "long" },
"name_suggest" : {
"type" : "completion",
"index_analyzer": "my_edge_ngram_analyzer",
"search_analyzer": "my_edge_ngram_analyzer"
}
}
}
}
}'
Here are examples to put into ES:
curl -X PUT localhost:9200/companies/company/1 -d '
{
"name" : "1800flowers",
"count": 1000,
"name_suggest" : {
"input" : [
"1800 flowers.Com, Inc",
"1800 Flowers","1800-Flowers.com",
"1 800 Flowers",
"www.1800flowers.com",
"1800Flowers.com",
"Inc,1-800-FLOWERS.COM",
"1-800-FLOWERS.COM, INC",
"1800Flowers",
"1800Flowers Inc",
"1800Flowers.com (Consultant)",
"1-800-FLOWERS","1800Flowers.com",
"1800FLOWERS INTERNATIONAL",
"1-800 Flowers",
"1-800 FLOWERS.COM, INC",
"1-800-FLOWERS, Inc",
"1800 flowers.com",
"1-800Flowers.com",
"1-800 flowers.com",
"1800 Flowers Inc"
],
"output" : "1800 Flowers"
}
}'
curl -X PUT localhost:9200/companies/company/2 -d '
{
"name" : "1800 Ruby",
"count": 10000,
"name_suggest" : {
"input" : [
"1800"
],
"output" : "1800 Ruby"
}
}'
Now clearly if I do a text search on 1800, I should get both of these objects back, giving output "1800 Flowers", "1800 Ruby".
Now really, I would like these results to be sorted by count, descending, so that I should have: "1800 Ruby", "1800 Flowers" but this isn't working!
curl -X POST localhost:9200/companies/_suggest -d '
{
"query":{
"companies" : {
"text" : "18",
"completion" : {
"field" : "name_suggest"
}
}
},
"sort": [ {"count": {"order": "desc"} } ]
}'
So in summary I would firstly like the output to be given, then secondly to list in sorted order by the property count.
Thanks