-
-
Save dadoonet/8842209 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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", | |
"index" : "not_analyzed", | |
"fields" : { | |
"ngram" : { | |
"type" : "string", | |
"index_analyzer" : "ngram" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
' 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