0

I have to search for a result with these conditions:

  1. filter:- make="FUSO" AND model="SUPERGRADE" AND is_vin_required="is_vin_required_1"
  2. should:- make="FUSO" AND is_vin_required="is_vin_required_0"

result should be union of both. I tried to add the same condition but the conditions in should are ignored. I also added

"minimum_should_match":1

but again same result.

I used this query:-

{
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {}
        },
        {
          "match": {
            "type": "product_abstract"
          }
        },
        {
          "match": {
            "store": "ZA"
          }
        },
        {
          "match": {
            "locale": "en_US"
          }
        },
        {
          "match": {
            "is-active": true
          }
        },
        {
          "bool": {
            "should": [
              {
                "range": {
                  "active-from": {
                    "lte": "now"
                  }
                }
              },
              {
                "bool": {
                  "must_not": [
                    {
                      "exists": {
                        "field": "active-from"
                      }
                    }
                  ]
                }
              }
            ]
          }
        },
        {
          "bool": {
            "should": [
              {
                "range": {
                  "active-to": {
                    "gte": "now"
                  }
                }
              },
              {
                "bool": {
                  "must_not": [
                    {
                      "exists": {
                        "field": "active-to"
                      }
                    }
                  ]
                }
              }
            ]
          }
        },
        {
          "bool": {}
        }
      ],
      "filter": [
        {
          "nested": {
            "query": {
              "term": {
                "integer-facet.facet-name": {
                  "value": "price-DEFAULT-ZAR-GROSS_MODE",
                  "boost": 1
                }
              }
            },
            "path": "integer-facet"
          }
        },
        {
          "bool": {
            "should": [
              {
                "nested": {
                  "path": "string-facet",
                  "query": {
                    "bool": {
                      "filter": [
                        {
                          "term": {
                            "string-facet.facet-name": {
                              "value": "make",
                              "boost": 1
                            }
                          }
                        },
                        {
                          "term": {
                            "string-facet.facet-value": {
                              "value": "FUSO",
                              "boost": 1
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "should": [
              {
                "nested": {
                  "path": "string-facet",
                  "query": {
                    "bool": {
                      "filter": [
                        {
                          "term": {
                            "string-facet.facet-name": {
                              "value": "model",
                              "boost": 1
                            }
                          }
                        },
                        {
                          "term": {
                            "string-facet.facet-value": {
                              "value": "SUPERGRADE",
                              "boost": 1
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            ]
          }
        }
      ],
      "should": [
        {
          "bool": {
            "must": [
              {
                "nested": {
                  "path": "string-facet",
                  "query": {
                    "bool": {
                      "filter": [
                        {
                          "term": {
                            "string-facet.facet-name": {
                              "value": "make",
                              "boost": 1
                            }
                          }
                        },
                        {
                          "term": {
                            "string-facet.facet-value": {
                              "value": "FUSO",
                              "boost": 1
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              },
              {
                "multi_match": {
                  "fields": [
                    "full-text",
                    "full-text-boosted^3"
                  ],
                  "query": "is_vin_required_0",
                  "type": "cross_fields"
                }
              }
            ]
          }
        }
      ],
      "minimum_should_match": 1,
      "boost": 1
    }
  }
}

No result was found with this query.

I tried with "minimum_should_match": 1 but still no result was found.

I also follow this article to achieve result:- Link

  • Could you edit the question to include the exact attributes that you wanted to include in the query? It's a bit hard to follow in the state that it is now. – jolammi Sep 02 '23 at 07:58
  • @jolammi I have modified attribute values. – sushant kumar Sep 02 '23 at 08:40
  • You want the results to have a strict requirement for make="FUSO" and model="SUPERGRADE". But what do you mean with the should clause, since there is also make="FUSO" in the should clause? Do all documents have the same fields in the index, or do the fields differ? Please elaborate more in your question of what you want to get in the results. – jolammi Sep 02 '23 at 09:45
  • @jolammi Actually i want this result. i hope this this will explain the scenario:- ** 1. filter:- make="FUSO" AND model="SUPERGRADE" AND is_vin_required="is_vin_required_1" . 2. ** should:- make="FUSO" AND is_vin_required="is_vin_required_0" . ** – sushant kumar Sep 02 '23 at 10:14
  • @jolammi Actually i want this result. i hope this this will explain the scenario:- ''' 1. filter:- make="FUSO" AND model="SUPERGRADE" AND is_vin_required="is_vin_required_1" . 2. should:- make="FUSO" AND is_vin_required="is_vin_required_0" . ''' – sushant kumar Sep 02 '23 at 10:21

0 Answers0