Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shairontoledo/0a33acea6f269c277058e078b7d02c21 to your computer and use it in GitHub Desktop.
Save shairontoledo/0a33acea6f269c277058e078b7d02c21 to your computer and use it in GitHub Desktop.
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