elasticsearch - Elasticsearch,对全文字符串进行过滤

标签 elasticsearch

我刚刚开始使用Elasticsearch,并且必须使用同事生成的数据。我注意到每个String数据都是全文值:

{
    "countryId": {
      "type": "string"
}

但是我们不需要进行全文搜索,因此使用过滤器搜索的确切值将是非常好的。唯一的问题是,由于时间不足,这些值的类型暂时无法更改。

所以我的问题是:如果我对全文值进行基于过滤器的搜索,将会发生什么?是否会像使用match搜索那样对搜索条件进行分析,或者过滤器会忽略此值的全文本类型并将其作为精确值进行处理,因为过滤器确实非常快,从而节省了大量搜索时间?

我仔细阅读了文档及其周围的内容,但没有明确的答案。

最佳答案

您可能已经凭经验观察到了尝试这种操作时会发生的情况,但是为了使term过滤器的行为符合预期(与指定字段中的指定参数完全匹配),索引的映射必须将字段的index属性定义为not_analyzedterm过滤器的官方文档是here,但是最直接相关的部分可能是:

Filters documents that have fields that contain a term (not analyzed).



因此,您的索引应具有与以下内容类似的定义映射:
{"mappings" : {"the_document_type": {
  "countryId" : {"type" : "string", "index" : "not_analyzed"},
  ...
  ... Mappings for other fields in your document
  ...
}}}

给定上面的代码段,包含文档要求精确匹配term的某些指定参数的countryId过滤器的查询应该成功。类似于以下内容:
{"query" : {"filtered" :
  "query" : {"match_all" : {}},
  "filter" : {"term" : {"countryId" : "Kingdom of Anvilania"}}
}}

Elasticsearch here中还有关于string类型(以及所有其他核心类型)的文档,但是有关index属性的特定部分是这样的:

Set to analyzed for the field to be indexed and searchable after being broken down into token using an analyzer. not_analyzed means that its still searchable, but does not go through any analysis process or broken down into tokens. no means that it won’t be searchable at all (as an individual field; it may still be included in _all). Setting to no disables include_in_all. Defaults to analyzed.

关于elasticsearch - Elasticsearch,对全文字符串进行过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28604142/

相关文章:

elasticsearch - 如何使用主管在 docker 容器上运行 elasticsearch?

elasticsearch - Elasticsearch 中的filterby,groupby唯一字段值,总和汇总,orderby查询链

elasticsearch - 聚合前 N 个结果

logging - Docker 容器中 Java 异常的 Filebeat 多行解析不起作用

elasticsearch - 如何在多重比对查询中限制结果?

docker - 在docker上安装特定版本的elasticsearch

elasticsearch - ElasticSearch聚合-按计数分组而不分析字段

elasticsearch - 使用ElasticSearch将在字段中共享相同ID的多个文档分组

elasticsearch - 如何汇总_score

python - 从 python 查询 elasticsearch 有什么更好的?