Elasticsearch查询搜索按关键字,然后按价格排序结果
这是我目前的搜索查询,
"query":{
"bool":{
"filter":[
{
"term":{
"status":{
"value":1
}
}
}
],
"should":[
{
"multi_match":{
"fields":[
"title",
"categories.title",
"subtitle"
],
"type":"most_fields",
"fuzziness":"AUTO",
"query":"GTX"
}
}
]
}
},
我要做的就是按价格上升顺序排序。但是,当我将价格放在排序中时,它将按顺序排列所有文档并忽略过滤器。 这是我的查询,
"sort": [
{
"_script":{
"type":"number",
"script":{
"lang":"painless",
"source":"if(Math.abs(doc['product_quantity'].value) > 0) { 1 } else { 0 }"
},
"order":"desc"
}
},
{
"_score": {
"order": "desc"
}
},
{
"price": {
"order": "desc"
}
}
],
我应该如何按价格按顺序排序搜索结果
this is my current search query
"query":{
"bool":{
"filter":[
{
"term":{
"status":{
"value":1
}
}
}
],
"should":[
{
"multi_match":{
"fields":[
"title",
"categories.title",
"subtitle"
],
"type":"most_fields",
"fuzziness":"AUTO",
"query":"GTX"
}
}
]
}
},
what i am trying to do is to sort by price in ascending order. but when i put price in my sort query it will sort all documents in ascending order and ignore the filters.
this is my sort query
"sort": [
{
"_script":{
"type":"number",
"script":{
"lang":"painless",
"source":"if(Math.abs(doc['product_quantity'].value) > 0) { 1 } else { 0 }"
},
"order":"desc"
}
},
{
"_score": {
"order": "desc"
}
},
{
"price": {
"order": "desc"
}
}
],
how should i sort the searched results in ascending order by price
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论