Skip to content

Instantly share code, notes, and snippets.

@dnsang
Last active August 29, 2015 14:22
Show Gist options
  • Save dnsang/3fc1dc88ab79342ff3bc to your computer and use it in GitHub Desktop.
Save dnsang/3fc1dc88ab79342ff3bc to your computer and use it in GitHub Desktop.
Exactly Match with Not_Analyzed & Term filter
#this gist is used to answer for question from http://stackoverflow.com/questions/30691082/elasticsearch-either-or-match-query
#any question could request to [email protected]
# delete exist index
curl -XDELETE 'http://localhost:9200/furnit/'
#create new index
curl -XPUT 'http://localhost:9200/furnit/'
# create a new type which specify mappings
curl -XPUT 'http://localhost:9200/furnit/_mappings/products' -d '{
"products" : {
"properties":{
"id":{"type": "long"},
"category": {"type": "string", "index" : "not_analyzed"}
}
}
}'
# index some product for test
curl -XPUT 'http://localhost:9200/furnit/products/1' -d '{
"id": 1,
"category": ["cate abc","cate xyz"]
}'
curl -XPUT 'http://localhost:9200/furnit/products/2' -d '{
"id": 2,
"category": ["cate abc","cate new"]
}'
#now find some product one cate abc, expect to get product 1 & 2
curl -XGET 'http://localhost:9200/furnit/products/_search' -d '{
"query":{ "match_all" : {} },
"filter": { "terms" : { "category" : ["cate abc"] } }
}
}'
#now find some product one cate xyz or cate new, expect to get product 1 & 2
curl -XGET 'http://localhost:9200/furnit/products/_search' -d '{
"query":{ "match_all" : {} },
"filter": { "terms" : { "category" : ["cate xyz","cate new"] } }
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment