0

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

arya_la
  • 399
  • 2
  • 10

0 Answers0