Elasticsearch Index Setting一覽表【轉】


原文地址:https://cloud.tencent.com/developer/article/1443568

 

索引的配置項按是否可以更改分為static屬性與動態配置,所謂的靜態配置即索引創建后不能修改。

索引靜態配置

  • index.number_of_shards 索引分片的數量。在ES層面可以通過es.index.max_number_of_shards屬性設置索引最大的分片數,默認為1024,index.number_of_shards的默認值為Math.min(es.index.max_number_of_shards,5),故通常默認值為5。
  • index.shard.check_on_startup 分片在打開之前是否應該檢查該分片是否損壞。當檢測到損壞時,它將阻止分片被打開。可選值:false:不檢測;checksum:只檢查物理結構;true:檢查物理和邏輯損壞,相對比較耗CPU;fix:類同與false,7.0版本后將廢棄。默認值:false。
  • index.codec 數據存儲的壓縮算法,默認值為LZ4,可選擇值best_compression ,比LZ4可以獲得更好的壓縮比(即占據較小的磁盤空間,但存儲性能比LZ4低)。
  • index.routing_partition_size 路由分區數,如果設置了該參數,其路由算法為:(hash(_routing) + hash(_id) % index.routing_parttion_size ) % number_of_shards。如果該值不設置,則路由算法為 hash(_routing) % number_of_shardings,_routing默認值為_id。

索引動態配置

  • index.number_of_replicas 索引復制分片的個數,默認值1,該值必須大於等於0,索引創建后該值可以變更。
  • index.auto_expand_replicas 副本數是否自動擴展,可設置(e.g0-5)或(0-all)。
  • index.refresh_interval 執行刷新操作的頻率,該操作使對索引的最新更改對搜索可見。默認為1s。可以設置為-1以禁用刷新。
  • index.max_result_window 控制分頁搜索總記錄數,from + size的大小不能超過該值,默認為10000。
  • index.max_inner_result_window 從from+ size的最大值,用於控制top aggregations,默認為100。內部命中和頂部命中聚合占用堆內存,並且時間與 from + size成正比,這限制了內存。
  • index.max_rescore_window 在rescore的搜索中,rescore請求的window_size的最大值。
  • index.max_docvalue_fields_search 一次查詢最多包含開啟doc_values字段的個數,默認為100。
  • index.max_script_fields 查詢中允許的最大script_fields數量。默認為32。
  • index.max_ngram_diff NGramTokenizer和NGramTokenFilter的min_gram和max_gram之間允許的最大差異。默認為1。
  • index.max_shingle_diff 對於ShingleTokenFilter, max_shingle_size和min_shingle_size之間允許的最大差異。默認為3。
  • index.blocks.read_only 索引數據、索引元數據是否只讀,如果設置為true,則不能修改索引數據,也不能修改索引元數據。
  • index.blocks.read_only_allow_delete 與index.blocks.read_only基本類似,唯一的區別是允許刪除動作。
  • index.blocks.read 設置為true以禁用對索引數據的讀取操作。
  • index.blocks.write 設置為true以禁用對索引數據的寫操作。(針對索引數據,而不是索引元數據)
  • index.blocks.metadata 設置為true,表示不允許對索引元數據進行讀與寫。
  • index.max_refresh_listeners 索引的每個分片上當刷新索引時最大的可用監聽器數量。這些偵聽器用於實現refresh=wait_for。
  • index.highlight.max_analyzed_offset 高亮顯示請求分析的最大字符數。此設置僅適用於在沒有偏移量或term vectors的文本字段時。默認情況下,該設置在6中未設置。x,默認值為-1。
  • index.max_terms_count 可以在terms查詢中使用的術語的最大數量。默認為65536。
  • index.routing.allocation.enable Allocation機制,其主要解決的是如何將索引在ES集群中在哪些節點上分配分片(例如在Node1是創建的主分片,在其他節點上創建復制分片)。舉個例子,如果集群中新增加了一個節點,集群的節點由原來的3個變成了4 可選值:
    1. all 所有類型的分片都可以重新分配,默認。
    2. primaries 只允許分配主分片。
    3. new_primaries 只允許分配新創建的主分片。
    4. none 所有的分片都不允許分配。
  • index.routing.rebalance.enable 索引的分片重新平衡機制。可選值如下:
    1. all 默認值,允許對所有分片進行再平衡。
    2. primaries 只允許對主分片進行再平衡。
    3. replicas 只允許對復制分片進行再平衡。
    4. none 不允許對任何分片進行再平衡
  • index.gc_deletes 文檔刪除后(刪除后版本號)還可以存活的周期,默認為60s。
  • index.max_regex_length 用於正在表達式查詢(regex query)正在表達式長度,默認為1000。
  • index.default_pipeline 默認的管道聚合器。

Analysis

分析模塊相關配置參數,將在后續分析模塊部分介紹。

Index Shard Allocation

索引分片分配相關參數。這部分內容將在Cluster(集群模塊詳細介紹)。

Mapping

字段映射相關參數,詳情請參考:Elasticsearch Mapping parameters(主要參數一覽)

Merging

后台分片合並進程相關配置參數。

  • index.merge.scheduler.max_thread_count 用於單個分片節點合並的最大線程數量,默認值為:Math.max(1, Math.min(4, Runtime.getRuntime().availableProcessors() / 2)),如果是非SSD盤,該值建議設置為1。

Similarities

相似性相關配置,這個后續可能會以專題介紹,暫不深究。

Show Log

慢查詢日志相關配置。

Search Show Log

首先ES提供在查詢階段(query)和數據獲取階段(fetch)設置闊值,超過該闊值則記錄日志。 支持如下參數:

1index.search.slowlog.threshold.query.warn: 10s 2index.search.slowlog.threshold.query.info: 5s 3index.search.slowlog.threshold.query.debug: 2s 4index.search.slowlog.threshold.query.trace: 500ms

上述參數定義查詢階段的闊值,分別表示,如果執行時間超過10s,打出警告日志,超過5s輸出info級別日志。

1index.search.slowlog.threshold.fetch.warn: 1s 2index.search.slowlog.threshold.fetch.info: 800ms 3index.search.slowlog.threshold.fetch.debug: 500ms 4index.search.slowlog.threshold.fetch.trace: 200ms

上述參數定義查詢獲取數據(fetch)的闊值,分別表示,如果執行時間超過1s,打出警告日志,超過800ms輸出info級別日志。

index.search.slowlog.level: info 定義日志輸出級別為info,也就是hdebug,trace級別的日志不輸出。

注意:上述日志級別為分片級日志。

上述參數定義了日志輸出級別,那接下來還需要在log4j文件中定義日志輸出器,日志輸出文件路徑等,其相關配置如下:

 1appender.index_search_slowlog_rolling.type = RollingFile 2appender.index_search_slowlog_rolling.name = index_search_slowlog_rolling 3appender.index_search_slowlog_rolling.fileName = ${sys:es.logs}_index_search_slowlog.log 4appender.index_search_slowlog_rolling.layout.type = PatternLayout 5appender.index_search_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] [%node_name]%marker %.10000m%n 6appender.index_search_slowlog_rolling.filePattern = ${sys:es.logs}_index_search_slowlog-%d{yyyy-MM-dd}.log 7appender.index_search_slowlog_rolling.policies.type = Policies // 文件切割方案,屬於log4j的語法 8appender.index_search_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy // 基於時間切割,log4j還支持按大小切割,其類為SizeBasedTriggeringPolicy。 9appender.index_search_slowlog_rolling.policies.time.interval = 1 // 1小時切割成一個文件 10appender.index_search_slowlog_rolling.policies.time.modulate = true // 是否修正時間范圍, 如果設置為true,則從0時開始計數 11 12logger.index_search_slowlog_rolling.name = index.search.slowlog 13logger.index_search_slowlog_rolling.level = trace 14logger.index_search_slowlog_rolling.appenderRef.index_search_slowlog_rolling.ref = index_search_slowlog_rolling 15logger.index_search_slowlog_rolling.additivity = false

Index Show Log

索引慢日志。

1index.indexing.slowlog.threshold.index.warn: 10s 2index.indexing.slowlog.threshold.index.info: 5s 3index.indexing.slowlog.threshold.index.debug: 2s 4index.indexing.slowlog.threshold.index.trace: 500ms 5index.indexing.slowlog.level: info 6index.indexing.slowlog.source: 1000 

index.indexing.slowlog.source參數用來控制記錄文檔_souce字段字符的個數,默認為1000,表示只記錄_souce字段的前1000個字符,可以設置true,表示輸出_souce字段全部內容,設置為false,表示不記錄_souce字段的內容。

默認情況下,會對_souce字段的輸出進行格式化,通常使用一行輸出,如果想阻止格式化,可以通過index.indexing.slowlog.reformat設置為false來避免。

同樣通過上述屬性定義好闊值,接下來將在logg4j配置文件中定義日志的輸出。

 1appender.index_indexing_slowlog_rolling.type = RollingFile 2appender.index_indexing_slowlog_rolling.name = index_indexing_slowlog_rolling 3appender.index_indexing_slowlog_rolling.fileName = ${sys:es.logs}_index_indexing_slowlog.log 4appender.index_indexing_slowlog_rolling.layout.type = PatternLayout 5appender.index_indexing_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] [%node_name]%marker %.-10000m%n 6appender.index_indexing_slowlog_rolling.filePattern = ${sys:es.logs}_index_indexing_slowlog-%d{yyyy-MM-dd}.log 7appender.index_indexing_slowlog_rolling.policies.type = Policies 8appender.index_indexing_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy 9appender.index_indexing_slowlog_rolling.policies.time.interval = 1 10appender.index_indexing_slowlog_rolling.policies.time.modulate = true 11 12logger.index_indexing_slowlog.name = index.indexing.slowlog.index 13logger.index_indexing_slowlog.level = trace 14logger.index_indexing_slowlog.appenderRef.index_indexing_slowlog_rolling.ref = index_indexing_slowlog_rolling 15logger.index_indexing_slowlog.additivity = false

store

存儲模塊,其主要參數為:index.store.type,表示存儲類型,該參數為靜態參數,在索引創建時指定,無法更改。 其可選值:

  • fs 默認文件系統實現,根據當前操作系統選擇最佳存儲方式。
  • simplefs 簡單的FS類型,使用隨機訪問文件實現文件系統存儲(映射到Lucene SimpleFsDirectory)。並發性能很差(多線程會出現瓶頸)。當需要索引持久性時,通常最好使用niofs。
  • niofs 基於NIOS實現的文件系統,該類型使用NIO在文件系統上存儲碎片索引(映射到Lucene NIOFSDirectory)。它允許多個線程同時從同一個文件中讀取數據。
  • mmapfs 基於文件內存映射機制實現的文件系統實現,該方式將文件映射到內存(MMap)來存儲文件系統上的碎片索引(映射到Lucene MMapDirectory)。內存映射使用進程中與被映射文件大小相同的部分虛擬內存地址空間。 可以通過node.store.allow_mmapfs屬性來禁用基於內存映射機制,如果節點所在的操作系統沒有大量的虛擬內存,則可以使用該屬性明確禁止使用該文件實現。

Translog

由於Lucene提交的開銷太大,不能每個單獨變更就提交(刷寫到磁盤),所以每個分片復制都有一個事務日志,稱為translog。所有索引(index)和刪除(delete)操作都是在被內部Lucene索引處理之后(但在它們被確認之前[返回客戶端])寫入translog的。在發生崩潰的情況下,當分片恢復時,可以從translog中恢復最近已確認但尚未包含在上一次Lucene提交中的事務。

Translog日志有點類似於關系型數據庫mysql的redo日志。

Translog相關配置參數(索引級別):

  • index.translog.durability translog刷盤方式,可選值:request、async。request,即每請求一次刷盤,也就是客戶端發起一個增刪改操作時,會在主分片與復制分片全部刷盤成功后,才會返回成功,是ES的默認模式。async:異步刷盤模式,此模式刷盤頻率由index.translog.sync_interval設置,其默認值為5s,該模式會存在數據丟失的可能。
  • index.translog.sync_interval 如果index.translog.durability設置為async,用該值來設置刷盤的頻率,默認為5s。
  • index.translog.flush_threshold_size es強制刷新的另外一個維度,如果translog的大小達到該值,則強制將未刷盤的數據強制刷新到Lucene中(類比一下關系型數據庫的數據文件),默認512mb。
  • index.translog.retention.size 保存跨日志文件的總大小。也就是一translog日志文件flush后,並不馬上刪除,而是保留一段時間,但最新的translog文件已存儲的內容與待刪除的文件的間隔不超過該參數設置的值,默認為512M。
  • index.translog.retention.age 保存translog文件的最大持續時間,默認為12 h。

關於ES的配置屬性就先介紹到這里,后續還會對Analysis、Index Shard Allocation、Similarities這三個模塊進行更加詳細的說明。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM