{
"from": 0,
"size": 100,
"timeout": "10m",
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"bool": {
"filter": [
{
"bool": {
"must": [
{
"term": {
"input.custom_attrs.index": {
"value": "1",
"boost": 1
}
}
}
]
}
},
{
"bool": {
"must": [
{
"prefix": {
"input.custom_attrs.value": {
"value": "An*",
"boost": 1
}
}
}
]
}
}
]
}
}
]
}
}
]
}
}
}
说明 - 我想搜索以“An”为前缀的字段。 另外,我确信存在值为“年度”和“年度基金”的数据,这些数据应该出现在所有匹配搜索中。 但是这些记录没有出现在上面给出的前缀查询中。我也尝试了正则表达式查询和通配符查询。但它们也不起作用。请提供您宝贵的建议,如何使查询工作。
最佳答案
无法正常工作的可能原因
看起来在索引数据时您使用了默认映射或文本字段,它使用 default standard analyzer它将生成的标记转换为小写。
同时prefix queries are not analyzed并且搜索词不会经过任何分析器,也不会被小写。
就您的情况而言,您正在搜索 An
,注意大写 A
,同时搜索 Annual
和 Annualfund
,代币将是年度
、年度
和基金
,因此它不匹配。
解决方案:
请使用 an
作为前缀查询,您应该会得到搜索结果。
关于elasticsearch - Elasticsearch 中的 prefixQuery 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61187082/