当在bool:{必须[…]}内使用多个query_string时,我试图对查询进行排序。
当我删除排序时,响应是ok的。当我只使用唯一的query_string时,我可以按created_by
排序有一些不可能使多个query_string和排序它们?
下面是查询:
{
index: "news",
size: 100,
from: 100,
body: {
query: {
bool: {
must: [
{
query_string: {
query: "(new york) or (big apple)",
fields: ["title", "description"],
},
},
{
range: {
created_by: {
gte: "now-90d",
lte: "now",
},
},
},
],
},
},
},
sort: [
{
created_by: {
order: "desc",
format: "strict_date_optional_time_nanos",
unmapped_type: "date",
},
},
"_score",
],
}
您的搜索查询中存在一些映射问题。查询的结构应该像
{
"query": {},
"sort": {}
}
修改查询,如下所示-
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "(new york) or (big apple)",
"fields": [
"title",
"description"
]
}
},
{
"range": {
"created_by": {
"gte": "now-90d",
"lte": "now"
}
}
}
]
} // note the extra bracket here
},
"sort": [
{
"created_by": {
"order": "desc",
"format": "strict_date_optional_time_nanos",
"unmapped_type": "date"
}
},
"_score"
]
}