Trp
Trp

Reputation: 184

General Search with array of objects

Anyone knows if it is possible to do the following search in elasticsearch without using scripts.

Any suggestion it is welcome, as I couldn't find anything in the documentation.

{
  "query": {
    "match": {
      "brands.*.shirts.colors": "red"
    }
  }
}

brands: arrays of objects of brand

*: any object of brand object

colors: array of colors

ps: the structure is merely illustrative.

Upvotes: 0

Views: 40

Answers (2)

Trp
Trp

Reputation: 184

Improving the answer of Val I got the code that works.

{
  "query": {
    "query_string": {
      "fields": ["brands.*.shirts.colors"],
      "query": "red"
    }
  }
}

Upvotes: 0

Val
Val

Reputation: 217274

Try with query_string like this:

{
  "query": {
    "query_string": {
      "query": "brands.\*.shirts.colors:red"
    }
  }
}

Upvotes: 1

Related Questions