Reputation: 4266
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?
Upvotes: 1
Views: 562
Reputation: 321
Checkout multi fields in elasticsearch http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#_multi_fields_3
Upvotes: 0
Reputation: 18864
To reference nested fields use the '.'-notation:
POST /<index-name>/_search
{
"query": {
"match": {
"traits.patience": "none"
}
}
}
Upvotes: 2