Noop Query

Hello,

I'm building a some-what generic converter from an object that contains lists of values, to a search requests for elasticsearch, for example:

{
    names: ["john", "bob"],
    cities: ["boston", "moscow"]
}

turns into

{
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "name": [
              "john",
              "bob"
            ]
          }
        },
        {
          "terms": {
            "city": [
              "boston",
              "moscow"
            ]
          }
        }
      ]
    }
  },
  "size": 1000
}

My problem is, one of the lists could be empty, and a terms query without any terms returns no results:

{
  "terms": {
    "city": []
  }
}

I could use the match_all query, but sometimes the original query is meant to be negated, meanining the top must clouse will be replaced with must_not and then the internal match_all will be replaced with match_none which makes the code very tiresome.

I'm looking for a way to create a "noop" query to just be ignored.

Thanks a lot.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.