Elasticsearch-选择要用于字段的分析器 [英] Elasticsearch - Choosing the analyzer to use for fields

查看:97
本文介绍了Elasticsearch-选择要用于字段的分析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何告诉 query_string 在搜索中使用哪个分析器?

How do I tell query_string which analyzer to use in a search?

我已经使用分析器创建了索引,如下所示:

I've created my index with an analyzer like so:

"analysis": {
  "analyzer": {
    "std_analyzer": {
      "tokenizer": "whitespace",
      "filter": [ "stemmer" ]
    }
  }
}

我没有预定义任何映射.相反,我依赖在插入文档时动态添加映射.

I do not predefine any mappings. Instead, I rely mappings to be dynamically added upon inserting a document.

调用/my_index/_mapping

      "short_bio" : {
        "type" : "text",
        "fields" : {
          "keyword" : {
            "type" : "keyword",
            "ignore_above" : 256
          }
        }
      },

动态添加字段时,您将在映射中看到没有定义的分析器.

You will see there no analyzer defined in the mapping when the field is added dynamically.

这是否意味着搜索将自动使用通过索引( std_analyzer )创建的分析器?还是使用其他分析仪?如何强制它使用我想要的分析仪?

Does this mean searching will automatically use the analyzer that was created with the index (std_analyzer)? Or is some other analyzer used? How do I force it to use the analyzer that I want?

如果相关,我正在使用 query_string 进行搜索以利用AND/OR/NOT/grouping

If's relevant, I'm searching using query_string to take advantage of AND/OR/NOT/grouping

谢谢!

推荐答案

请从

(可选,字符串)分析器,用于转换查询字符串中的文本代币.默认为映射到的索引时间分析器default_field.如果未映射任何分析器,则索引的默认分析器使用.

(Optional, string) Analyzer used to convert text in the query string into tokens. Defaults to the index-time analyzer mapped for the default_field. If no analyzer is mapped, the index’s default analyzer is used.

这意味着,由于您尚未定义任何显式分析器,查询字符串将对文本字段使用标准分析器,对 keyword 字段使用关键字aka no-op分析器./strong>

It means in your case, as you have not defined any explicit analyzer, query string will use the standard analyzer for text fields and keyword aka no-op analyzer for keyword fields.

也不要与索引的默认分析器混淆,您可以按照

Also don't be confused with index's default analyzer, you can simply check this by following this official link.

也如文档中所述,查询字符串返回错误的语法错误,并且首选

Also as mentioned in the docs, query string returns errors for invalid syntax and your use-case of AND/OR/NOT can be easily handled by preferred boolean query

这篇关于Elasticsearch-选择要用于字段的分析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆