0

I want to create the equivalent of the following query:

(country.id = 2000 AND natureservices.id = 2000 AND metiers.id = 1000) AND (shortname = "shortname" OR fullname = "fullname" OR categories.id = 1000 OR specialities.id = 2000)

in my case he must show me a single result but when i tried the below query it show many results

{ "query": {
   "bool": {
        "must": [
            { "term": { "country.id": 2000 } },
            { "term": { "natureservices.id": 2000 } },
            { "term": { "metiers.id": 1000 } },
            {
                "bool": {
                    "should": [
                        { "term": { "shortname": "vgftQzSPwW" } },
                        { "term": { "fullname": "qcouWRzFNG" } },
                        { "term": { "categories.id": 1000 } },
                        { "term": { "specialities.id": 2000 } }
                    ], "minimum_should_match": 4
                }
            }
        ], "minimum_should_match": 3
    }
 } } 

1 Answer 1

0

Please read here . I have correct your query literally, but I can't understand why you are using a minimum_should_match clause in that way. minimum_should_match usually is used when you have more clauses than the number you specify there. For example if you have 4 should clauses, but for some reason you only need three of them to be fulfilled, you would assign 3 as value of minimum_should_match . According me this use of minimum_should_match could creates problems, so i have expunged minimum_should_match from your query. The correct syntax of your query is:

{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "country.id": 2000
                }
              },
              {
                "term": {
                  "natureservices.id": 2000
                }
              },
              {
                "term": {
                  "metiers.id": 1000
                }
              }
            ]
          }
        },
        {
          "bool": {
            "should": [
              {
                "term": {
                  "shortname": "vgftQzSPwW"
                }
              },
              {
                "term": {
                  "fullname": "qcouWRzFNG"
                }
              },
              {
                "term": {
                  "categories.id": 1000
                }
              },
              {
                "term": {
                  "specialities.id": 2000
                }
              }
            ]
          }
        }
      ]
    }
  }
} 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer. How can i modify this query according to this condition: if(valueShortName != null) { shortname = valueShortName} OR if(valueFullName != null) { fullname = valueFullName }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.