Last active
November 14, 2018 12:42
-
-
Save djptek/75f952791a1406b32951b2266d155e7d to your computer and use it in GitHub Desktop.
Nested Addresses - Do not need nested type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example: for example i have a person with nested- adresses. and query name of person with city and zip of the adress in one query? | |
| PUT clients/_doc/1 | |
| { | |
| "client": "dp", | |
| "address": { | |
| "city": "north", | |
| "zip": "1234" | |
| } | |
| } | |
| PUT clients/_doc/2 | |
| { | |
| "client": "ds", | |
| "address": { | |
| "city": "south", | |
| "zip": "5678" | |
| } | |
| } | |
| PUT clients/_doc/3 | |
| { | |
| "client": "ds", | |
| "address": { | |
| "city": "el norte", | |
| "zip": "1234" | |
| } | |
| } | |
| # this query matches 2 _docs | |
| GET clients/_search | |
| { | |
| "query": { | |
| "bool": { | |
| "must": [ | |
| {"match": { | |
| "address.zip.keyword": "1234" | |
| }} | |
| ] | |
| } | |
| } | |
| } | |
| # this query matches only one _doc | |
| GET clients/_search | |
| { | |
| "query": { | |
| "bool": { | |
| "must": [ | |
| {"match": { | |
| "address.zip.keyword": "1234" | |
| }}, | |
| {"match": { | |
| "address.city.keyword": "north" | |
| }} | |
| ] | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment