Skip to content

Instantly share code, notes, and snippets.

@jeantil
Created May 29, 2015 13:26
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 jeantil/8eadcea6cc1574dd5764 to your computer and use it in GitHub Desktop.
Save jeantil/8eadcea6cc1574dd5764 to your computer and use it in GitHub Desktop.
Exact Filter on array field in elasticsearch
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