[英]Boost Elastic Search results at the query time based on the last indexed time
我試圖弄清楚如何根據上次索引時間提高搜索結果的相關性。 因此,如果搜索查詢有多個匹配項,我需要根據文檔的最后索引時間戳來提升結果。
我嘗試按照此處的文檔進行操作,並嘗試執行一些查詢,但不確定如何傳遞字段名稱及其值。
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_value
是false
,那么我們不能對該字段進行排序或聚合。 這是彈性搜索方面的限制。 我嘗試使用doc_value
為true
創建新索引,它按預期工作。
您不能在此處使用field_value_factor
,因為它只能接受一個數字作為參數。 您必須使用其他函數(例如gauss
)來確定較新記錄的優先級。
它可能看起來像這樣:
{
"query": {
"function_score": {
"query": {
"match": {
"content": "sample"
}
},
"functions": [
{
"gauss": {
"indexedTimeStamp": {
"origin": "now",
"scale": "30d"
}
}
}
]
}
}
}
如果doc_value
為false
,則我們無法對該字段進行排序或聚合。 我們也不能更新該字段。 這是彈性搜索方面的限制。 我嘗試使用doc_value
為true
創建新索引,它按預期工作。
更多信息在這里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.