我遇到了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