Skip to content

Instantly share code, notes, and snippets.

@djptek
Last active November 14, 2018 12:42
Show Gist options
  • Select an option

  • Save djptek/75f952791a1406b32951b2266d155e7d to your computer and use it in GitHub Desktop.

Select an option

Save djptek/75f952791a1406b32951b2266d155e7d to your computer and use it in GitHub Desktop.
Nested Addresses - Do not need nested type
# 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