Я пытаюсь найти город, используя query_string и звездочку (query: `${city}*`
), а также фильтрую результаты по countryId
.
Запрос работает хорошо без фильтрации для countryId, но при добавлении фильтра он ничего не находит. Boty city
и countryId
были отображены как text
.
Код:
const elasticsearch = require('elasticsearch');
...
this.client = new elasticsearch.Client({
hosts: [this._serviceUri]
});
...
// The interesting part:
const results = await this.client.search({
index: 'cities',
body: {
query: {
query_string: {
query: `${city}*`,
fields: ['city', 'countryId'],
// type: 'best_fields'
}
},
post_filter: { term: { countryId } }
}
});
Как правильно отфильтровать результаты с помощью post_filter или чего-то подобного?
UPDATE:
Вот как выглядит отображение:
mappings: {
_doc: {
properties: {
"city": {type: 'text'},
"countryId": {type: 'text'}
}
}
}