0
似乎,我有排序结果的问题。下面是我的配置:ElasticSearch - 排序不起作用
curl -X PUT localhost:9200/companies -d '
{
"settings" : {
"analysis" : {
"analyzer" : {
"my_edge_ngram_analyzer" : {
"tokenizer" : "my_edge_ngram_tokenizer"
}
},
"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"
}
}
}
}
}'
下面举例来投入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"
}
}'
现在清楚,如果我在1800做一个文本搜索,我应该得到两个对象回来,给人输出“ 1800朵花“,”1800红宝石“。
现在真的,我想这些结果按count,降序排序,所以我应该有:“1800红宝石”,“1800花”,但这是行不通的!
curl -X POST localhost:9200/companies/_suggest -d '
{
"query":{
"companies" : {
"text" : "18",
"completion" : {
"field" : "name_suggest"
}
}
},
"sort": [ {"count": {"order": "desc"} } ]
}'
似乎工作正常。你知道一种简单引用count属性的方法,而不是写两次吗? – redrubia
不幸的是,我无法找到一个。据我所知,完成的一个限制条件表明了这一点。 –