賞金將在 5 天后到期。此問題的答案有資格獲得 100聲望賞金。 R2D2正在從有信譽的來源尋找答案。
我對重新索引有疑問,我不確定 100% 我找到的解決方案是最好的,因為我們在處理來自 java 客戶端的索引時遇到問題。所以我想確認重新索引步驟是否正確:
問題描述:我在舊的 v1.7 上有一個索引,需要遷移到使用背景關系提示器的 elasticsearch v7.x。
GET /autocompleteterms_v20/_search?pretty
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 4130,
"max_score" : 1.0,
"hits" : [ {
"_index" : "autocompleteterms_v20",
"_type" : "autoitem",
"_id" : "en_incorporated_by_reference",
"_score" : 1.0,
"_source":{ "name": "incorporated by reference", "name_suggest": { "input": "incorporated by reference", "context": { "lang": "en" }, "weight": 393 } }
}, {
"_index" : "autocompleteterms_v20",
"_type" : "autoitem",
"_id" : "en_double_gaming",
"_score" : 1.0,
"_source":{ "name": "double gaming", "name_suggest": { "input": "double gaming", "context": {
"lang": "en" }, "weight": 371 } }
}, {
"_index" : "autocompleteterms_v20",
"_type" : "autoitem",
"_id" : "en_checking_for_players",
"_score" : 1.0,
"_source":{ "name": "checking for players", "name_suggest": { "input": "checking for players",
"context": { "lang": "en" }, "weight": 2 } }
},
GET /autocompleteterms_v20/_mapping?pretty
{
"autocompleteterms_v20" : {
"mappings" : {
"autoitem" : {
"properties" : {
"name" : {
"type" : "string"
},
"name_suggest" : {
"type" : "completion",
"analyzer" : "standard",
"payloads" : true,
"preserve_separators" : false,
"preserve_position_increments" : false,
"max_input_length" : 50,
"context" : {
"lang" : {
"type" : "category",
"path" : "lang_field",
"default" : [ "en" ]
}
}
}
}
}
}
}
}
為了重新索引到新集群,我發現建議者在 v5 中有一些重大更改,因此當嘗試轉換重新索引上的索引欄位時
首先我創建映射:
PUT autocompleteterms_v20 { "settings": { "index": { "number_of_shards": 2, "number_of_replicas": 0 } }, "mappings": { "properties": { "name": { "type": "text" }, "name_suggest": { "type": "completion", "analyzer": "standard", "preserve_separators": false, "preserve_position_increments": false, "max_input_length": 50, "contexts": [ { "name": "lang", "type": "category", "path": "lang_field" } ] } } } } { "acknowledged" : true, "shards_acknowledged" : true, "index" : "autocompleteterms_v20" }之后,我重新索引將欄位背景關系更改為背景關系:
POST _reindex { "source": { "remote": { "host": http://x.x.x.x:9200, "username": "user", "password": "password" }, "index": "autocompleteterms_v20" }, "dest": { "index": "autocompleteterms_v20" }, "script": { "source": """ ctx._source.name_suggest.contexts = ctx._source.name_suggest.context; ctx._source['name_suggest'].remove('context'); """, "lang": "painless" } } { "took" : 366, "timed_out" : false, "total" : 4130, "updated" : 0, "created" : 4130, "deleted" : 0, "batches" : 5, "version_conflicts" : 0, "noops" : 0, "retries" : { "bulk" : 0, "search" : 0 }, "throttled_millis" : 0, "requests_per_second" : -1.0, "throttled_until_millis" : 0, "failures" : [ ] }當我使用顯式背景關系進行查詢時,我得到結果:
POST /autocompleteterms_v20/_search { "suggest": { "text": "spirit", "completion": { "field": "name_suggest", "contexts": { "lang": [ { "context": "en" } ] } } } } } { "took" : 5, "timed_out" : false, "_shards" : { "total" : 2, "successful" : 2, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 0, "relation" : "eq" }, "max_score" : null, "hits" : [ ] }, "suggest" : { "completeMe" : [ { "text" : "spirit", "offset" : 0, "length" : 6, "options" : [ { "text" : "spirit", "_index" : "autocompleteterms_v20", "_type" : "_doc", "_id" : "en_spirit", "_score" : 290.0, "_source" : { "name_suggest" : { "input" : "spirit", "weight" : 290, "contexts" : { "lang" : "en" } }, "name" : "spirit" }, "contexts" : { "lang" : [ "en" ] } }, { "text" : "spirit of the game", "_index" : "autocompleteterms_v20", "_type" : "_doc", "_id" : "en_spirit_of_the_game", "_score" : 34.0, "_source" : { "name_suggest" : { "input" : "spirit of the game", "weight" : 34, "contexts" : { "lang" : "en" } }, "name" : "spirit of the game" }, "contexts" : { "lang" : [ "en" ] } }但是,當我在沒有背景關系的情況下進行查詢時,會出現錯誤:
POST /autocompleteterms_v20/_search { "suggest": { "completeMe": { "text": "spirit", "completion": { "field": "name_suggest" } } } } { "error" : { "root_cause" : [ { "type" : "illegal_argument_exception", "reason" : "Missing mandatory contexts in context query" } ], "type" : "search_phase_execution_exception", "reason" : "all shards failed", "phase" : "query", "grouped" : true, "failed_shards" : [ { "shard" : 0, "index" : "autocompleteterms_v20", "node" : "B7EpKWRVRzGkLCnl7CZapQ", "reason" : { "type" : "illegal_argument_exception", "reason" : "Missing mandatory contexts in context query" } } ], "caused_by" : { "type" : "illegal_argument_exception", "reason" : "Missing mandatory contexts in context query", "caused_by" : { "type" : "illegal_argument_exception", "reason" : "Missing mandatory contexts in context query" } } }, "status" : 400 }
但在 v5.0 的重大變化中,我們有https://www.elastic.co/guide/en/elasticsearch/reference/5.0/break_50_suggester.html#_completion_mapping_with_multiple_contexts
提到:“針對啟用背景關系的完成欄位沒有背景關系的新查詢會產生所有索引建議的結果”
在這種情況下,我有兩個主要問題:
- 舊索引的重新索引是否正確完成?
- 如何在不針對該索引選擇背景關系的情況下進行查詢?
uj5u.com熱心網友回復:
是的,你做的一切都是正確的!
你不能,因為 ES 7.0 中的另一個建議器更改使得提供背景關系是強制性的,否則性能會下降太多
背景關系完成建議器
在 6.x 中已棄用的在沒有背景關系的情況下查詢和索引啟用背景關系的建議的功能已被洗掉。沒有背景關系的背景關系啟用建議查詢必須訪問每個建議,這會大大降低搜索性能。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/481757.html
