Skip to content

Instantly share code, notes, and snippets.

@derickson
Last active August 29, 2015 14:26
Show Gist options
  • Save derickson/2afb9fe0a5b31af62239 to your computer and use it in GitHub Desktop.
Save derickson/2afb9fe0a5b31af62239 to your computer and use it in GitHub Desktop.
Quick test for Elasticsearch in sense to prove Alias filters correctly work with searches, facet term counts, and global aggregation. proves that term suggester doesn't respect alias filter
DELETE /foo
PUT /foo
{
"settings": {
"number_of_replicas": 0,
"number_of_shards": 1
},
"mappings": {
"people": {
"properties": {
"name": { "type": "string", "index": "analyzed"},
"cat" : { "type": "string", "index": "not_analyzed"},
"secLabel": { "type": "string", "index": "not_analyzed"},
"notes": {"type": "string", "copy_to": "_sugTarg"},
"notes2": {"type": "string", "copy_to": "_sugTarg"}
}
}
}
}
POST /_aliases
{
"actions" : [
{
"add" : {
"index" : "foo",
"alias" : "fooA",
"filter" : { "term" : { "secLabel" : "A" } }
},
"add" : {
"index" : "foo",
"alias" : "fooB",
"filter" : { "term" : { "secLabel" : "B" } }
},
"add" : {
"index" : "foo",
"alias" : "fooC",
"filter" : { "term" : { "secLabel" : "C" } }
}
}
]
}
POST /foo/people/_bulk
{"index":{"_id":1}}
{name:"David A", cat:"AA", secLabel:"A", "notes":"apple america"}
{"index":{"_id":2}}
{name:"David A", cat:"AB", secLabel:"A", "notes": "answer", "notes2": "anaconda"}
{"index":{"_id":3}}
{name:"David A", cat:"AC", secLabel:"A", "notes": "abacus"}
{"index":{"_id":4}}
{name:"David B", cat:"BA", secLabel:"B", "notes": "banana"}
{"index":{"_id":5}}
{name:"David B", cat:"BB", secLabel:"B", "notes": "bonzai"}
{"index":{"_id":6}}
{name:"David B", cat:"BC", secLabel:"B", "notes": "bolo"}
{"index":{"_id":7}}
{name:"David C", cat:"CA", secLabel:"C", "notes": "catamaran"}
{"index":{"_id":8}}
{name:"David C", cat:"CB", secLabel:"C", "notes": "car"}
{"index":{"_id":9}}
{name:"David C", cat:"CC", secLabel:"C", "notes": "calzone"}
{"index":{"_id":10}}
{name:"David C", cat:"AA", secLabel:"C"}
GET /foo/_search?pretty
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"term": {
"secLabel": "A"
}
}
}
}
}
GET /_cat/aliases
GET /fooA/_search?pretty
GET /fooB/_search?pretty
GET /fooC/_search?pretty
## correctly gives facet counts, even in the global zone
GET fooA/_search?search_type=count&pretty
{
"aggs": {
"cats": {
"terms": {
"field": "cat",
"size": 10
}
},
"all_customers": {
"global": {},
"aggs": {
"cats": {
"terms": {
"field": "cat",
"size": 10
}
}
}
}
}
}
## correctly suggests for america
GET fooA/_search?search_type=count&pretty
{
"suggest" : {
"noteSug" : {
"text" : "ameri",
"term" : { "field" : "_sugTarg"}
}
}
}
# jumps outside the filter for the alias to get banana
GET fooA/_search?search_type=count&pretty
{
"suggest" : {
"noteSug" : {
"text" : "bana",
"term" : { "field" : "_sugTarg"}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment