Я пытаюсь запросить мой индекс ElasticSearch, чтобы получить элементы, которые одно из полей "foo" начинается с "hel".
Поле toto имеет тип ключевого слова:
"toto": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
Это то, что я пытался:
client.search({index: 'xxxxx', type: 'xxxxxx_type', body: {"query": {"regexp": {"toto": "hel.*"}}}},
function(err, resp, status) {
if (err)
res.send(err)
else {
console.log(resp);
res.send(resp.hits.hits)
}
});
Я пытался найти решение здесь:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-regexp-query.html
и
https://www.elastic.co/guide/en/elasticsearch/guide/current/_wildcard_and_regexp_queries.html
или здесь
Как искать часть слова с ElasticSearch
но ничего не работает.
Вот так выглядят мои данные:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "xxxxxx",
"_type": "xxxxx_type",
"_id": "1",
"_score": 1,
"_source": {
"toto": "hello"
}
}
}