Created
May 29, 2015 13:26
-
-
Save jeantil/8eadcea6cc1574dd5764 to your computer and use it in GitHub Desktop.
Exact Filter on array field in elasticsearch
This file contains 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
DELETE /blog | |
PUT /blog | |
{ | |
"settings":{ | |
"analysis":{ | |
"analyzer":{ | |
"mykeyword":{ | |
"type":"custom", | |
"tokenizer":"keyword" | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"articles":{ | |
"properties": { | |
"tags":{ | |
"type": "string" | |
, "index": "not_analyzed" | |
}, | |
"tagz":{ | |
"type": "string" | |
, "analyzer": "mykeyword" | |
} | |
} | |
} | |
} | |
} | |
GET /blog/articles/_mapping | |
PUT /blog/articles/1 | |
{ | |
"tags":["UPPER","lower"], | |
"tagz":["UPPER","lower"] | |
} | |
PUT /blog/articles/2 | |
{ | |
"tags":["UPPER"], | |
"tagz":["UPPER"] | |
} | |
PUT /blog/articles/3 | |
{ | |
"tags":["lower"], | |
"tagz":["lower"] | |
} | |
GET /blog/articles/_search | |
GET /blog/articles/_search | |
{ | |
"query": {"filtered": { | |
"query": {"match_all": {}}, | |
"filter": { | |
"bool": {"must": [ | |
{"term": { | |
"tags": "UPPER" | |
}} | |
]} | |
} | |
}} | |
} | |
GET /blog/articles/_search | |
{ | |
"query": {"filtered": { | |
"query": {"match_all": {}}, | |
"filter": { | |
"bool": {"must": [ | |
{"term": { | |
"tagz": "UPPER" | |
}} | |
]} | |
} | |
}} | |
} | |
GET /blog/articles/_search | |
{ | |
"query": {"filtered": { | |
"query": {"match_all": {}}, | |
"filter": { | |
"bool": {"must": [ | |
{"term": { | |
"tagz": "upper" | |
}} | |
]} | |
} | |
}} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment