elasticsearch - How to aggregate by substring in elasticseach -
i have index many document this:
post /example/doc { id : "type-name", foo: bar } and retrieve list of type present. example
post /example/doc { id : "aaa-123", foo: bar } post /example/doc { id : "aaa-456", foo: bar } post /example/doc { id : "bbb-123", foo: bar } and ask elasticseaarch give me list have aaa , bbb.
update i've solved using custom analyzer
"settings": { "analysis": { "char_filter" : { "remove_after_minus":{ "type":"pattern_replace", "pattern":"-(.*)", "replacement":"" } }, "analyzer": { "id_analyzer":{ "tokenizer" : "standard", "char_filter" : ["remove_after_minus"] } } } }
if keep standard analyzer, id split @ "-". so, if types lower , upper case same, can go simple facet query
curl -xpost "http://localhost:9023/index/type/_search?size=0&pretty=true" -d '{ "query" : { { "regexp":{ "id": "[a-z]+" } }, "facets" : { "id" : { "terms" : { "field" : "id", "size" : 50 } } } }' should give somtehing can use.
Comments
Post a Comment