【发布时间】:2016-04-02 07:52:18
【问题描述】:
我在使用 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 等)?
-
谢谢,我正在使用 python (elasticsearch-dsl.readthedocs.org/en/latest)。问题是弹性搜索总是返回相同的结果。查询部分可以正常工作,但是对于 asc 和 desc 订单返回相同的列表。
-
你能展示你正在使用的python代码吗?
-
title字段的映射是什么? -
编辑了更多细节。谢谢。
标签: sorting elasticsearch elasticsearch-dsl elasticsearch-py