Skip to content

Instantly share code, notes, and snippets.

@jessejlt
Created February 1, 2012 22:22
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 jessejlt/1719842 to your computer and use it in GitHub Desktop.
Save jessejlt/1719842 to your computer and use it in GitHub Desktop.
curl -XDELETE localhost:9200
curl -XPOST localhost:9200/test/tools -d '
{
"type": "crayon",
"color": "red"
}'
curl -XPOST localhost:9200/test/tools -d '
{
"type": "crayon",
"color": "green"
}'
curl -XPOST localhost:9200/test/tools -d '
{
"type": "paint",
"color": "blue",
"applicator": "finger"
}'
curl -XPOST localhost:9200/test/tools -d '
{
"type": "paint",
"color": "red",
"applicator": "brush"
}'
want <crayon> AND <paint>
if <paint>
want <applicator> is "brush"
sample query:
curl -XGET localhost:9200/test/_search?pretty=true -d '
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"terms": {
"type": ["crayon", "paint"]
}
}
]
}
}
}
}'
but this doesn't do anything for {applicator: "brush"}
solution:
curl -XGET localhost:9200/test/_search?pretty=true -d '
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"or": [
{
"term": {"type": "crayon"}
},
{
"and": [
{
"term": {"type": "paint"}
},
{
"term": {"applicator": "brush"}
}
]
}
]
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment