【问题标题】:Boost Elastic Search results at the query time based on the last indexed time根据上次索引时间在查询时间提升 Elastic Search 结果
【发布时间】:2019-11-01 09:15:49
【问题描述】:

我试图弄清楚如何根据上次索引时间提高搜索结果的相关性。因此,如果搜索查询有多个匹配项,我需要根据文档的最后索引时间戳来提升结果。

我已尝试遵循文档here,并尝试执行一些查询,但不确定如何传递字段名称及其值。

GET code_sourcenodedupefilecontractv4_1421_shared_5dd3788f-2d0a-4a49-b679-98bbf519013e/_search
{
  "query": {
    "function_score": {
      "query": {
        "match": {
          "originalContent": "sample"
        }
      },
      "functions": [
        {
          "linear": {
            "indexedTimeStamp": {
              "scale": "30d",
              "decay": 0.5
            }
          }
        }
      ]
    }
  }
}

在 kibana 中执行上述查询时,我收到以下消息:

"failed_shards": [
  {
    "shard": 0,
    "index": "code_sourcenodedupefilecontractv4_1421_shared_5dd3788f-2d0a-4a49-b679-98bbf519013e",
    "node": "UX5mwT1sT_a2QuqeFG-JUw",
    "reason": {
      "type": "query_shard_exception",
      "reason": "failed to create query: {\n  \"function_score\" : {\n    \"query\" : {\n      \"match\" : {\n        \"originalContent\" : {\n          \"query\" : \"sample\",\n          \"operator\" : \"OR\",\n          \"prefix_length\" : 0,\n          \"max_expansions\" : 50,\n          \"fuzzy_transpositions\" : true,\n          \"lenient\" : false,\n          \"zero_terms_query\" : \"NONE\",\n          \"auto_generate_synonyms_phrase_query\" : true,\n          \"boost\" : 1.0\n        }\n      }\n    },\n    \"functions\" : [\n      {\n        \"filter\" : {\n          \"match_all\" : {\n            \"boost\" : 1.0\n          }\n        },\n        \"linear\" : {\n          \"indexedTimeStamp\" : {\n            \"scale\" : \"30d\",\n            \"decay\" : 0.5\n          },\n          \"multi_value_mode\" : \"MIN\"\n        }\n      }\n    ],\n    \"score_mode\" : \"multiply\",\n    \"max_boost\" : 3.4028235E38,\n    \"boost\" : 1.0\n  }\n}",
      "index_uuid": "U6os7SW0QuqOuuS3sASCrg",
      "index": "code_sourcenodedupefilecontractv4_1421_shared_5dd3788f-2d0a-4a49-b679-98bbf519013e",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "Can't load fielddata on [indexedTimeStamp] because fielddata is unsupported on fields of type [date]. Use doc values instead."
      }
    }
  }
]"
      

弹性搜索中存储的字段(indexedTimeStamp)的值为:

"indexedTimeStamp": {
        "type": "date",
        "store": true,
        "doc_values": false,
        "format": "epoch_second"
      },

我错过了什么吗?

[编辑]:如果doc_valuefalse,那么我们不能对该字段进行排序或聚合。这是弹性搜索方面的限制。我尝试使用doc_value 作为true 创建新索引,它按预期工作。

【问题讨论】:

    标签: elasticsearch kibana


    【解决方案1】:

    你不能在这里使用field_value_factor,因为它只能接受一个数字作为参数。您必须使用其他函数(例如 gauss)来优先处理较新的记录。

    它可能看起来像这样:

    {
      "query": {
        "function_score": {
          "query": {
            "match": {
              "content": "sample"
            }
          },
          "functions": [
            {
              "gauss": {
                "indexedTimeStamp": {
                  "origin": "now",
                  "scale": "30d"
                }
              }
            }
          ]
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      如果doc_valuefalse,那么我们不能对该字段进行排序或聚合。我们也不能更新该字段。这是弹性搜索方面的限制。我尝试使用 doc_value 作为 true 创建新索引,它按预期工作。

      更多信息here

      【讨论】:

        猜你喜欢
        • 2012-05-18
        • 2017-05-26
        • 2011-10-02
        • 1970-01-01
        • 1970-01-01
        • 2013-10-10
        • 2020-07-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多