elasticsearch - Elasticsearch查询结果与分析字符串不一致

标签 elasticsearch

我有一个属性 edApp.name 我通过匹配查询。我已经确认映射为“type”:“string”,因此应进行分析。

当我进行匹配查询时,每次获得的点击次数都不同。

无论是使用/ _search还是通过读取别名来查询所有文档,我都会看到相同的行为。

较新的更新:动态映射的字段似乎是罪魁祸首。该字段由 generate.edApp.name 生成,并使用“not_analyzed”动态映射。一旦为具有该字段的文档建立索引, edApp.name 的分析器便会中断,并且我开始看到匹配查询的奇怪结果。

文件:

{
  @context: "http://purl.imsglobal.org/ctx/caliper/v1/Context",
  edApp: {
    name: "ReadingRainbow"
  }
}

映射:
"dynamic_templates": [
          {
            "string_theory": {
              "mapping": {
                "index": "not_analyzed",
                "type": "string",
                "doc_values": true
              },
              "match": "*",
              "match_mapping_type": "string"
            }
          },
          {
            "i_dont_know_you": {
              "mapping": {
                "enabled": false
              },
              "match_mapping_type": "object",
              "path_match": "*.extensions.*"
            }
          }
   ],
   "properties": {
        "_all": {
          "enabled": false
        },
        "_timestamp": {
          "enabled": true
        },
...
      "edApp": {
        "properties": {
           "name": {
              "type": "string"
           }
        }
     }
}

查询返回不一致的结果:
{
  "query": {
      "match": {
          "edApp.name": "ReadingRainbow"
      }
   }
}

多次运行查询时的hits.total值:[44、56、57、69]

字词查询返回不一致的结果:
{
    "query": {
        "bool": {
            "should": [
            {
                "term": {
                    "edApp.name": "ReadingWonders2.0"
                }
            }
            ]
        }
    }
}

多次运行术语查询时,hits.total值:[21、33、34、46]

其他术语查询返回不一致的结果(注意小写):
{
    "query": {
        "bool": {
            "should": [
            {
                "term": {
                    "edApp.name": "readingwonders2.0"
                }
            }
            ]
        }
    }
}

多次运行字词查询时,hits.total值:[44、56、57、69]
注意:这些与我们在匹配查询中看到的计数相同!

用两个词查询:
{
    "query": {
        "bool": {
            "should": [
            {
                "term": {
                    "edApp.name": "readingwonders2.0"
                }
            },
            {
                "term": {
                    "edApp.name": "ReadingWonders2.0"
                }
            }
            ]
        }
    }
}

hits.total值一致:79个结果

如您所见,小写和驼峰词条搜索中不一致的匹配项最多可添加79个文档。分析仪会造成这种不一致吗?

我正在使用AWS Elasticsearch Service ES 1.5.2

最佳答案

动态映射的属性 generate.edApp.name edApp.name 冲突。

edApp.name 被明确映射为“已分析”

生成.edApp.name 动态映射为“未分析”

一旦动态属性存在, edApp.name 的匹配查询就会中断。

我的解决方法是添加动态模板来处理与显式映射的分析字符串共享名称的字段

"dynamic_templates": [
          {
            "analyzed_string_theory": {
              "mapping": {
                "index": "analyzed",
                "type": "string"
              },
              "match_pattern": "regex",
              "match": "^.*name|.*keywords|.*description$"
            }
          },
      {
        "string_theory": {
          "mapping": {
            "index": "not_analyzed",
            "type": "string"
          },
          "match_mapping_type": "string",
          "match": "*"
        }
      },
     ... 
]

关于elasticsearch - Elasticsearch查询结果与分析字符串不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38928244/

相关文章:

java - 如何更新标准 token 生成器的 token

elasticsearch - 可以在Elasticsearch查询中从另一个索引中过滤一个索引的记录吗?

elasticsearch - 如何在ElasticSearch中使用过滤器?

elasticsearch - 在Elasticsearch中将选择具有特定字段的文档设置为NULL

amazon-web-services - 将日志从 ECS Fargate 发送到 Elasticsearch 的最佳方法

elasticsearch - 在具有2GB RAM的计算机上引导elasticsearch

elasticsearch - 为什么Elastic Search返回此记录?

sorting - Elasticsearch 中的耦合

ruby-on-rails - Elasticsearch错误

macos - 如何在macOS中安装elasticsearch5.6?