我遇到了elasticsearch查询的问题。 我希望能够排序结果,但elasticsearch忽略排序标记。在这里我的查询:Elasticsearch没有对结果进行排序
{
"sort": [{
"title": {"order": "desc"}
}],
"query":{
"term": { "title": "pagos" }
}
}
然而,当我删除查询的一部分,我只发送排序的标签,它的工作原理。 任何人都可以指出我的正确方法吗?
我也试着用下面的查询,这是我有完整的查询:
{
"sort": [{
"title": {"order": "asc"}
}],
"query":{
"bool":{
"should":[
{
"match":{
"title":{
"query":"Pagos",
"boost":9
}
}
},
{
"match":{
"description":{
"query":"Pagos",
"boost":5
}
}
},
{
"match":{
"keywords":{
"query":"Pagos",
"boost":3
}
}
},
{
"match":{
"owner":{
"query":"Pagos",
"boost":2
}
}
}
]
}
}
}
设置
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "ngram",
"min_gram": 3,
"max_gram": 15,
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
},
"analyzer": {
"default" : {
"tokenizer" : "standard",
"filter" : ["standard", "lowercase", "asciifolding"]
},
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding",
"autocomplete_filter"
]
}
}
}
}
}
映射
{
"objects": {
"properties": {
"id": { "type": "string", "index": "not_analyzed" },
"type": { "type": "string" },
"title": { "type": "string", "boost": 9, "analyzer": "autocomplete", "search_analyzer": "standard" },
"owner": { "type": "string", "boost": 2 },
"description": { "type": "string", "boost": 4 },
"keywords": { "type": "string", "boost": 1 }
}
}
}
谢谢提前!
什么结果你得到和你有什么期望?还请说明你如何发送你的查询(curl,Java,Python,Sense等)? – Val
谢谢,我正在使用python(http://elasticsearch-dsl.readthedocs.org/en/latest/)。问题是elasticsearch总是返回相同的结果。查询部分工作正常,但返回相同的列表为asc和desc命令。 –
你能显示你正在使用的Python代码吗? – Val