Skip to content

Instantly share code, notes, and snippets.

@ariasdelrio
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ariasdelrio/8842138 to your computer and use it in GitHub Desktop.
Save ariasdelrio/8842138 to your computer and use it in GitHub Desktop.
multi_field and faceting in ES 1.0rc1
# Delete index
curl -s -X DELETE "http://$host:$port/multi_field_facetting" 2>&1 > /dev/null
# Create index
curl -s -X POST "http://$host:$port/multi_field_facetting" -d '
{
"settings" : {
"index": {
"analysis" : {
"filter" : {
"ngram" : {
"min_gram" : "1",
"type" : "nGram",
"max_gram" : "100"
}
},
"analyzer": {
"ngram" : {
"type" : "custom",
"filter" : [ "ngram" ],
"tokenizer" : "keyword"
}
}
}
}
}
}
' 2>&1 > /dev/null
# Create mapping (remove "index_analyzer" and it works)
curl -s -X PUT "http://$host:$port/multi_field_facetting/mytype/_mapping" -d '
{
"mytype": {
"dynamic" : "false",
"index_analyzer" : "ngram",
"properties": {
"myobject": {
"properties": {
"myproperty": {
"type": "string",
"fields" : {
"ngram" : {
"type" : "string",
"index_analyzer" : "ngram"
},
"myproperty" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}
}
}
}
}
}
' 2>&1 > /dev/null
# Index some documents
curl -s -X POST "http://$host:$port/multi_field_facetting/mytype/1" -d '{ "myobject": { "myproperty": "something" } }' 2>&1 > /dev/null
curl -s -X POST "http://$host:$port/multi_field_facetting/mytype/2" -d '{ "myobject": { "myproperty": "something" } }' 2>&1 > /dev/null
curl -s -X POST "http://$host:$port/multi_field_facetting/mytype/3" -d '{ "myobject": { "myproperty": "someone" } }' 2>&1 > /dev/null
sleep 1
# Search and facet
curl -s -X POST "http://$host:$port/multi_field_facetting/mytype/_search" -d '
{
"size": 0,
"query": {
"match": {
"myobject.myproperty.ngram": "some"
}
},
"facets": {
"myfacet": {
"terms": {
"order": "term",
"fields": [ "myobject.myproperty" ]
}
}
}
}
' | python -mjson.tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment