'How can I combine free where filter in Elasticsearch JAVA version?

I am deploying a new project with Elastic with elasticsearch-rest-client version 7.

Currently I work with SQL and I have a free filter in which the user writes the free query, for example (field1=24 OR field1 = 22 ) AND (field3 IS NULL OR field3 != 2).

And adding this part to the final query in SQL ORACLE is easy as long as there is no syntax error, but now in the Elasticsearch JAVA library I don't know how to transform said filter into a search with BoolQueryBuilder or any other constructor, I also have to add that must be combined with other BoolQueryBuilder filters.

could I put a series of filters with BoolQueryBuilder + free conditional where?

Any help is appreciated, even if it's just an approximation. Greetings



Solution 1:[1]

I think that query maybe be this:

{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "term": {
                  "num1": {
                    "value": 22
                  }
                }
              },
              {
                "term": {
                  "num1": {
                    "value": 24
                  }
                }
              }
            ]
          }
        },
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "must_not": [
                    {
                      "exists": {"field": "num3"}
                    }
                  ]
                }
              },
              {
                "term": {
                  "num3": {
                    "value": 1
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rabbit