gpt4 book ai didi

elasticsearch - ElasticSearch过滤时忽略排序

转载 作者:行者123 更新时间:2023-12-03 00:43:53 25 4
gpt4 key购买 nike

ElasticSearch版本:0.90.1,JVM:1.6.0_51(20.51-b01-457)

我正在尝试对我的ElasticSearch查询做两件事:1)根据 bool(boolean) 值(可搜索)和“open_date <明天”过滤结果; 2)两种按字段“open_date” DESC排序

这将产生以下查询:

{
"query": {
"bool": {
"should": [
{
"prefix": {
"name": "foobar"
}
},
{
"query_string": {
"query": "foobar"
}
},
{
"match": {
"name": {
"query": "foobar"
}
}
}
],
"minimum_number_should_match": 1
},
"filtered": {
"filter": {
"and": [
{
"term": {
"searchable": true
}
},
{
"range": {
"open_date": {
"lt": "2013-07-16"
}
}
}
]
}
}
},
"sort": [
{
"open_date": "desc"
}
]
}

但是,返回的结果未按“open_date”排序。如果删除过滤器:
{
"query": {
"bool": {
"should": [
{
"prefix": {
"name": "foobar"
}
},
{
"query_string": {
"query": "foobar"
}
},
{
"match": {
"name": {
"query": "foobar"
}
}
}
],
"minimum_number_should_match": 1
}
},
"sort": [
{
"open_date": "desc"
}
]
}

...结果按预期返回。

有任何想法吗?

最佳答案

我不确定Tyre代码,但是JSON无法正确构造过滤查询。我的猜测是,这会溢出并导致sort元素也无法正确解析。

过滤后的查询应该像这样构造(请参阅http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query/):

{
"query": {
"filtered": { // Note: this contains both query and filter
"query": {
"bool": {
"should": [
{
"prefix": {
"name": "foobar"
}
},
{
"query_string": {
"query": "foobar"
}
},
{
"match": {
"name": {
"query": "foobar"
}
}
}
],
"minimum_number_should_match": 1
}
},
"filter": {
"and": [
{
"term": {
"searchable": true
}
},
{
"range": {
"open_date": {
"lt": "2013-07-16"
}
}
}
]
}
}
},
"sort": [
{
"open_date": "desc"
}
]
}

干杯,
波阿斯

关于elasticsearch - ElasticSearch过滤时忽略排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17658745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com