Created
February 1, 2012 22:22
-
-
Save jessejlt/1719842 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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