Skip to content

Instantly share code, notes, and snippets.

@martijnvg
Created February 6, 2013 10:12
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 martijnvg/4721628 to your computer and use it in GitHub Desktop.
Save martijnvg/4721628 to your computer and use it in GitHub Desktop.
curl -s -XDELETE 'http://localhost:9200/test-idx'
echo
curl -s -XPUT 'http://localhost:9200/test-idx' -d '{
"settings": {
"index.number_of_shards" : 1
},
"mappings" : {
"document" : {
"properties" : {
"tags" : {
"type" : "nested",
"properties" : {
"tag" : { "type" : "string", "index": "not_analyzed" },
"active": {"type": "boolean"}
}
},
"title" : { "type" : "string" },
"category": {"type": "string", "index": "not_analyzed" }
}
}
}
}
'
echo
curl -s -XPUT 'http://localhost:9200/test-idx/document/1' -d '{
"title": "search engine",
"category": "page",
"tags": [{
"tag": "AAA",
"active": true
}, {
"tag": "111",
"active": false
}
]
}'
echo
curl -s -XPUT 'http://localhost:9200/test-idx/document/2' -d '{
"title": "elastic search",
"category": "blog",
"tags": [{
"tag": "BBB",
"active": true
}, {
"tag": "222",
"active": false
}]
}'
echo
curl -s -XPUT 'http://localhost:9200/test-idx/document/3' -d '{
"title": "lucene",
"category": "post",
"tags": [{
"tag": "CCC",
"active": true
}, {
"tag": "333",
"active": false
}]
}'
echo
curl -s -XPOST 'http://localhost:9200/test-idx/_refresh'
echo
echo "boolean: nested first"
curl -s -XGET 'http://localhost:9200/test-idx/document/_search?pretty=true' -d '{
"query": {
"bool": {
"must": [{
"nested" : {
"path": "tags",
"query": {
"term": {
"tags.active": true
}
}
}
}, {
"text" : {
"title": "search"
}
}]
}
},
"facets": {
"test" : {
"terms" : {
"field" : "tags.tag"
},
"facet_filter": {
"nested" : {
"path": "tags",
"query": {
"term": {
"tags.active": true
}
},
"join" : false
}
},
"nested" : "tags"
}
},
"fields": ["title"]
}'
echo
echo "boolean: nested last"
curl -s -XGET 'http://localhost:9200/test-idx/document/_search?pretty=true' -d '{
"query": {
"bool": {
"must": [{
"text" : {
"title": "search"
}
}, {
"nested" : {
"path": "tags",
"query": {
"term": {
"tags.active": true
}
}
}
}]
}
},
"facets": {
"test" : {
"terms" : {
"field" : "tags.tag"
},
"facet_filter" : {
"nested" : {
"path": "tags",
"query": {
"term": {
"tags.active": true
}
},
"join" : false
}
},
"nested": "tags"
}
},
"fields": ["title"]
}'
echo
echo "boolean: nested in the middle"
curl -s -XGET 'http://localhost:9200/test-idx/document/_search?pretty=true' -d '{
"query": {
"bool": {
"must": [{
"text" : {
"title": "search"
}
}, {
"nested" : {
"path": "tags",
"query": {
"term": {
"tags.active": true
}
}
}
}, {
"term" : {
"category": "blog"
}
}]
}
},
"facets": {
"test" : {
"terms" : {
"field" : "tags.tag"
},
"facet_filter" : {
"nested" : {
"path": "tags",
"query": {
"term": {
"tags.active": true
}
},
"join" : false
}
},
"nested": "tags"
}
},
"fields": ["title"]
}'
echo
echo "filtered: nested as filter"
curl -s -XGET 'http://localhost:9200/test-idx/document/_search?pretty=true' -d '{
"query" : {
"filtered" : {
"query": {
"text" : {
"title": "search"
}
},
"filter": {
"nested" : {
"path": "tags",
"query": {
"term": {
"tags.active": true
}
}
}
}
}
},
"facets": {
"test" : {
"terms" : {
"field" : "tags.tag"
},
"facet_filter" : {
"nested" : {
"path": "tags",
"query": {
"term": {
"tags.active": true
}
},
"join" : false
}
},
"nested": "tags"
}
},
"fields": ["title"]
}'
echo
echo "filtered: nested as query"
curl -s -XGET 'http://localhost:9200/test-idx/document/_search?pretty=true' -d '{
"query" : {
"filtered" : {
"query": {
"nested" : {
"path": "tags",
"query": {
"term": {
"tags.active": true
}
}
}
},
"filter": {
"query": {
"term": {
"title": "search"
}
}
}
}
},
"facets": {
"test" : {
"terms" : {
"field" : "tags.tag"
},
"facet_filter" : {
"nested" : {
"path": "tags",
"query": {
"term": {
"tags.active": true
}
},
"join" : false
}
},
"nested": "tags"
}
},
"fields": ["title"]
}'
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment