【问题标题】:ELASTICSEARCH: Comma separated list giving inconsistent results with standard analyzerELASTICSEARCH:逗号分隔列表与标准分析仪给出不一致的结果
【发布时间】:2019-04-04 04:06:01
【问题描述】:

对我的弹性搜索数据库运行基本查询会给出不一致的结果。

我可以直接匹配通过ID查询的数据库

{
    "query": {
        "bool": {
          "must": [
            {
              "term": {
                "id": {
                  "value": "84e042ce-74e3-4c51-a1d9-db2f1c3d57ef"
                }
              }
            }
          ]
        }
    }
}

这会按预期返回一条记录(显示 2 个字段)

"id": "84e042ce-74e3-4c51-a1d9-db2f1c3d57ef",
"usersNotified": "e721a8d9-8001-4003-9af9-1c7397fd7079,fc18bbc4-f7f1-4151-bf88-390597da9510,061c9195-cb97-4777-8577-a8e555b95c7f,8e4e7641-b135-46e5-b9b4-c42393450108,601785e7-1c18-43b4-924e-cf52a15e3204,ec132f25-3d1d-41d8-ab16-e60a53ee9483"

当我向查询中添加 match_phrase 以查找“usersNotified”字段中存在的 Guid 时,它返回为空。

{
    "query": {
        "bool": {
          "must": [
            {
              "term": {
                "id": {
                  "value": "84e042ce-74e3-4c51-a1d9-db2f1c3d57ef"
                }
              }
            },
            {
              "match_phrase": {
                "usersNotified": {
                  "query": "601785e7-1c18-43b4-924e-cf52a15e3204"
                }
              }
            }
          ]
        }
    }
}

{
    "took": 4,
    "timed_out": false,
    "_shards": {
        "total": 20,
        "successful": 20,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 0,
        "max_score": null,
        "hits": []
    }
}

对不同记录的完全相同的查询(以及较短的 usersNotified 列表)确实成功返回了匹配项

{
    "query": {
        "bool": {
          "must": [
            {
              "term": {
                "id": {
                  "value": "d48e6ccc-f343-4840-af29-317fef829da1"
                }
              }
            },
            {
              "match_phrase": {
                "usersNotified": {
                  "query": "601785e7-1c18-43b4-924e-cf52a15e3204"
                }
              }
            }
          ]
        }
    }
}

如图:

"id": "d48e6ccc-f343-4840-af29-317fef829da1",
"usersNotified": "e721a8d9-8001-4003-9af9-1c7397fd7079,fdc40427-9db0-44d8-8ce3-45c90489dc19,061c9195-cb97-4777-8577-a8e555b95c7f,601785e7-1c18-43b4-924e-cf52a15e3204,ec132f25-3d1d-41d8-ab16-e60a53ee9483"

所以我不明白为什么相同的查询在一种情况下有效,但在另一种情况下无效。任何帮助将不胜感激。

【问题讨论】:

  • 能否提供样本数据?
  • 我已经包含了上面的相关字段。 (“id”和“usersNotified”)在每个查询之后。不幸的是,我不能发布更多内容,因为它包含敏感信息

标签: elasticsearch


【解决方案1】:

所以我认为我已经解决了这个问题,但我无法完全测试它(并且无法进行几个冲刺......所以我想我会更新我所拥有的)。

我认为我的字段中的 UID 不匹配的原因是为该字段定义的标准分析器正在使用基于语言的算法进行分析,并将 GUID 中的破折号视为连字符并将它们从考虑中删除。

我仍然不明白为什么它有时会匹配而不是其他匹配,但是按照SO article,我能够重新扫描一个小子集并获得所需的结果。

基本上,我创建了一个自定义分析器,将字段标记为逗号分隔列表。然后我换了

{
"query": {
    "bool": {
      "must": [
        {
          "term": {
            "id": {
              "value": "d48e6ccc-f343-4840-af29-317fef829da1"
            }
          }
        },
        {
          "match_phrase": {
            "usersNotified": {
              "query": "601785e7-1c18-43b4-924e-cf52a15e3204"
            }
          }
        }
      ]
    }
}

与

{
"query": {
    "bool": {
      "must": [
        {
          "term": {
            "id": {
              "value": "d48e6ccc-f343-4840-af29-317fef829da1"
            }
          }
        },
        {
           "term": {
               "userssNotified": {
                   "value": "601785e7-1c18-43b4-924e-cf52a15e3204"
               }
           }
        }
      ]
    }
}

它奏效了。稍后我将有机会尝试使用完整的数据集(需要重新扫描)以查看它是否有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多