【问题标题】:Elastic Search | How to get original search query with corresponding match value弹性搜索 |如何获取具有相应匹配值的原始搜索查询
【发布时间】:2019-07-31 12:23:11
【问题描述】:

我使用 ElasticSearch 作为人力资源数据库的搜索引擎。

用户提交一个权限(f.ex 'disruption'),ElasticSearch 返回所有按最佳匹配排序的用户。

我已将“能力”字段配置为使用同义词,因此“创新”将匹配“颠覆”。

我想向用户(正在执行搜索的用户)展示特定搜索结果如何匹配搜索查询。为此,我使用explain api (reference)

查询按预期工作,并向每个hit 返回一个_explanation。 特定命中的详细信息(稍微简化)如下所示:

{
   description: "weight(Synonym(skills:innovation skills:disruption)),
   value: 3.0988
}

问题:我看不到 _explanation 中的原始搜索词。 (如上例所示:我可以看到一些搜索查询与“创新”或“颠覆”相匹配,我需要知道用户搜索的技能是什么)

问题:有什么办法可以解决这个问题(例如:将包含搜索查询标签信息的自定义“描述”解析为_explanation)?

预期结果:

{
   description: "weight(Synonym(skills:innovation skills:disruption)),
   value: 3.0988
   customDescription: 'innovation'
}

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    也许您可以将原始查询放在_name 字段中?

    就像https://qbox.io/blog/elasticsearch-named-queries中解释的那样:

    GET /_search
    {
        "query": {
            "query_string" : {
                "default_field" : "skills",
                "query" : "disruption",
                "_name": "disruption"
            }
        }
    }
    

    然后您可以在返回对象的 matched queries 部分中找到 proginal 查询:

    {
      "_index": "testindex",
      "_type": "employee",
      "_id": "2",
      "_score": 0.19178301,
      "_source": {
        "skills": "disruption"
      },
      "matched_queries": [
        "disruption"
      ]
    }
    

    explain 添加到解决方案中,我认为它可以正常工作...?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 1970-01-01
      • 2014-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多