1

Say I have the following JSON object

{
  "name" : "Hulk",
  "traits" : {
    "colour" : "green",
    "patience" : "none"
  }
}

I want to be able to search using a term like "traits:patience". What is the best approach?

To make things clearer (hopefully), here is another example, say I have the following object

{
  "characters": {
    "hulk": {
      "strength": 100,
      "specialty": "smash"
    },
    "cyclops": {
      "strength": 25,
      "specialty": "lasers"
    }
  }
}

Ideally, I want to be able to search using the term hulk:specialty and get back smash. Is this possible?

2 Answers 2

2

To reference nested fields use the '.'-notation:

POST /<index-name>/_search
{
    "query": {
        "match": {
            "traits.patience": "none"
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Checkout multi fields in elasticsearch http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#_multi_fields_3

Comments

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.