JSON syntax for a combined query using a structured query

59 views Asked by At

I'm programatically building a combined query to use with the /v1/search REST endpoint and I'm just a bit confused about the correct syntax for a combined query that contains a structured query. The combined query starts with a search element and a query element contains the structured query. The structured query example I coudl find start with a query element and put the queries into a queries array. So that means my combined query would look like:

{ "search": {
  "query": {
    "query": { 
      "queries": [
        {"term-query":{"text":["foo"]}}
      ]
    }
  }
}}

So what I guess I'm really asking is it /search/query/query/queries[] or is it /search/query/queries[]?

1

There are 1 answers

0
grtjn On

The extra query.queries looks a bit odd, but it is conform syntax, and works. You can also drop the term-query (or any other query) directly under search.query. This works too:

{
  "search": {
    "query": {
      "and-query": {
        "queries": []
      }
    }
  }
}

HTH!