Ответ 1
terms
-фильтр работает так, как вы ожидаете. Я думаю, ваша проблема здесь в том, что у вас есть сопоставление, где feed_uids
использует стандартный анализатор.
Это довольно распространенная проблема, которая описана здесь немного более подробно: Поиск и устранение неисправностей Поиск Elasticsearch для начинающих
Вот пример запуска, демонстрирующий, как он работает, если вы укажете "index": "not_analyzed"
для поля: https://www.found.no/play/gist/bc957d515597ec8262ab
#!/bin/bash
export ELASTICSEARCH_ENDPOINT="http://localhost:9200"
# Create indexes
curl -XPUT "$ELASTICSEARCH_ENDPOINT/play" -d '{
"mappings": {
"type": {
"properties": {
"feed_uids": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}'
# Index documents
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_bulk?refresh=true" -d '
{"index":{"_index":"play","_type":"type"}}
{"feed_uids":["math.CO","cs.IT"]}
{"index":{"_index":"play","_type":"type"}}
{"feed_uids":["cs.IT"]}
'
# Do searches
curl -XPOST "$ELASTICSEARCH_ENDPOINT/_search?pretty" -d '
{
"query": {
"filtered": {
"filter": {
"terms": {
"feed_uids": [
"cs.IT"
]
}
}
}
}
}
'