2016-05-30 56 views
0

我想索引10億條記錄。每個記錄有2個屬性(屬性1和屬性2)。 屬性1中具有相同值的每條記錄都必須合併。例如,我有兩個記錄在ElasticSearch建立索引後搜索

attribute1 attribute2 
1 4 
1 6 

我的彈性文檔必須

{ 
    "attribute1": "1" 
    "attribute2": "4,6" 
} 

由於數據量巨大,我一定要讀批量(大約1000條記錄),並根據它們合併上面的規則(在內存中),然後在ElasticSearch中搜索它們並將它們與搜索結果合併,然後對它們進行索引/重新索引。 總之,我必須分別搜索和索引每個散裝。 我實現了這條規則,但在某些情況下,Elastic不會返回所有結果,並且某些文檔已被重複編入索引。 之後每個索引我刷新ElasticSearch,以便它準備好下一個搜索。但在某些情況下,它不起作用。 我的索引設置之後爲:

{ 
"test_index": { 
    "settings": { 
     "index": { 
      "refresh_interval": "-1", 
      "translog": { 
       "flush_threshold_size": "1g" 
      }, 
      "max_result_window": "1000000", 
      "creation_date": "1464577964635", 
      "store": { 
       "throttle": { 
        "type": "merge" 
       } 
      } 
     }, 
     "number_of_replicas": "0", 
     "uuid": "TZOse2tLRqGk-vHRMGc2GQ", 
     "version": { 
      "created": "2030199" 
     }, 
     "warmer": { 
      "enabled": "false" 
     }, 
     "indices": { 
      "memory": { 
       "index_buffer_size": "40%" 
      } 
     }, 
     "number_of_shards": "5", 
     "merge": { 
      "policy": { 
       "max_merge_size": "2g" 
      } 
     } 
    } 
} 

我怎樣才能解決這個問題呢?

是否有其他設置來處理這種情況?

回答

0

在批量命令,你需要使用index操作中第一次出現,然後update用一個腳本來更新您的attribute2屬性:

{ "index" : { "_index" : "test_index", "_type" : "test_type", "_id" : "1" } } 
{ "attribute1" : "1", "attribute2": [4] } 
{ "update" : { "_index" : "test_index", "_type" : "test_type", "_id" : "1" } } 
{ "script" : { "inline": "ctx._source.attribute2 += attr2", "params" : {"attr2" : 6}}} 

第一index操作後您的文檔會像

{ 
    "attribute1": "1" 
    "attribute2": [4] 
} 

第二update手術後,你的文檔會像

{ 
    "attribute1": "1" 
    "attribute2": [4, 6] 
} 

請注意,也可以僅使用update操作doc_as_upsertscript

+0

我的問題是爲什麼有時當我索引數據並刷新彈性,並立即搜索它時,彈性不返回結果? – Ghasem

+0

如何刷新您的索引?我看到'refresh_interval'設置爲-1,意思是「永不刷新」。批量索引後的 – Val

+0

。我使用API​​調用刷新。 – Ghasem