Created
April 20, 2017 15:37
-
-
Save shairontoledo/0a33acea6f269c277058e078b7d02c21 to your computer and use it in GitHub Desktop.
This file contains 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
curl -XDELETE http://localhost:9200/my_index | |
sleep 3 | |
curl -XPUT "http://localhost:9200/my_index" -d ' | |
{ | |
"mappings": { | |
"blogpost": { | |
"properties": { | |
"comments": { | |
"type": "nested", | |
"properties": { | |
"name": { "type": "keyword" }, | |
"age": { "type": "short" } | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
echo "index doc1" | |
curl "http://localhost:9200/my_index/blogpost/1" -d ' | |
{ | |
"title": "doc1", | |
"comments": [ | |
{ | |
"name": "John Smith", | |
"age": 28 | |
}, | |
{ | |
"name": "Alice White", | |
"age": 31 | |
} | |
] | |
} | |
' | |
echo "index doc2" | |
curl "http://localhost:9200/my_index/blogpost/2" -d ' | |
{ | |
"title": "doc2", | |
"comments": [ | |
{ | |
"name": "Luther Lawrence", | |
"age": 21 | |
}, | |
{ | |
"name": "Alice White", | |
"age": 19 | |
} | |
] | |
} | |
' | |
echo "index doc3" | |
curl "http://localhost:9200/my_index/blogpost/3" -d ' | |
{ | |
"title": "doc3", | |
"comments": [ | |
{ | |
"name": "Tadhg Darragh", | |
"age": 22 | |
}, | |
{ | |
"name": "Alice White", | |
"age": 31 | |
}, | |
{ | |
"name": "Lorene Hicks", | |
"age": 44 | |
} | |
] | |
} | |
' | |
curl "http://localhost:9200/my_index/blogpost/_search" -d ' | |
{ | |
"_source": { "include": "title" }, | |
"query": { | |
"nested": { | |
"path": "comments", | |
"query": { | |
"bool": { | |
"must": [ | |
{ "term": { "comments.name": "John Smith" } }, | |
{ "term": { "comments.name": "Alice White" } } | |
] | |
} | |
} | |
} | |
} | |
} | |
' | |
curl "http://localhost:9200/my_index/blogpost/_search" -d ' | |
{ | |
"_source": { "include": "title" }, | |
"query": { | |
"nested": { | |
"path": "comments", | |
"query": { | |
"bool": { | |
"must": [ | |
{ "terms": { "comments.name": ["John Smith", "Alice White"] } } | |
] | |
} | |
} | |
} | |
} | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment