elasticsearch - Elasticsearch 中的 prefixQuery 不起作用

标签 elasticsearch elasticsearch-query

{
  "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,同时搜索 AnnualAnnualfund,代币将是年度年度基金,因此它不匹配。

解决方案:

请使用 an 作为前缀查询,您应该会得到搜索结果。

关于elasticsearch - Elasticsearch 中的 prefixQuery 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61187082/

相关文章:

elasticsearch - ElasticSearch:[multi_match]查询不支持[search_analyzer]

elasticsearch - 通过查询进行的 Elasticsearch 更新未反射(reflect)正确更新的文档数

elasticsearch - elasticsearch多字段查询未按预期工作

elasticsearch - Elasticsearch集群运行状况间歇性地在 'GREEN'和 'YELLOW'之间摆动

c# - Elasticsearch 中数据继承的最佳方法是什么?

elasticsearch - 在Elasticsearch Spark中将EPOCH转换为日期

ruby-on-rails - Searchkick 只返回某些值,而不是全部

elasticsearch - 在多个条件下查询 Elasticsearch

Elasticsearch 检查对象中是否存在键

elasticsearch - 如何在Elastic Search中使用Standard Analyzer分析文本