2016-03-02 44 views
1

我米试图指数在ES一些数据和I M个接收出存储器的异常:出的存储器中ElasticSearch

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space 
    at org.elasticsearch.common.jackson.core.util.BufferRecycler.balloc(BufferRecycler.java:155) 
    at org.elasticsearch.common.jackson.core.util.BufferRecycler.allocByteBuffer(BufferRecycler.java:96) 
    at org.elasticsearch.common.jackson.core.util.BufferRecycler.allocByteBuffer(BufferRecycler.java:86) 
    at org.elasticsearch.common.jackson.core.io.IOContext.allocWriteEncodingBuffer(IOContext.java:152) 
    at org.elasticsearch.common.jackson.core.json.UTF8JsonGenerator.<init>(UTF8JsonGenerator.java:123) 
    at org.elasticsearch.common.jackson.core.JsonFactory._createUTF8Generator(JsonFactory.java:1284) 
    at org.elasticsearch.common.jackson.core.JsonFactory.createGenerator(JsonFactory.java:1016) 
    at org.elasticsearch.common.xcontent.json.JsonXContent.createGenerator(JsonXContent.java:68) 
    at org.elasticsearch.common.xcontent.XContentBuilder.<init>(XContentBuilder.java:96) 
    at org.elasticsearch.common.xcontent.XContentBuilder.builder(XContentBuilder.java:77) 
    at org.elasticsearch.common.xcontent.json.JsonXContent.contentBuilder(JsonXContent.java:38) 
    at org.elasticsearch.common.xcontent.XContentFactory.contentBuilder(XContentFactory.java:122) 
    at org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder(XContentFactory.java:49) 
    at EsController.importProductEs(EsController.java:60) 
    at Parser.fromCsvToJson(Parser.java:120) 
    at CsvToJsonParser.parseProductFeeds(CsvToJsonParser.java:43) 
    at MainParser.main(MainParser.java:49) 

这是我的实例化ES客户端:

System.out.println("Elastic search client is instantiated"); 
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch_brew").build(); 
client = new TransportClient(settings); 
String hostname = "localhost"; 
int port = 9300; 
((TransportClient) client).addTransportAddress(new InetSocketTransportAddress(hostname, port));  
bulkRequest = client.prepareBulk(); 

和然后我运行批量请求:

// for each product in the list, we need to include the fields in the bulk request 
for(HashMap<String, String> productfields : products) 
     try { 
      bulkRequest.add(client.prepareIndex(index,type,productfields.get("Product_Id")) 
        .setSource(jsonBuilder() 
           .startObject() 
            .field("Name",productfields.get("Name")) 
            .field("Quantity",productfields.get("Quantity")) 
            .field("Make", productfields.get("Make")) 
            .field("Price", productfields.get("Price")) 
           .endObject() 
          ) 
        );     

     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
//execute the bulk request 
BulkResponse bulkResponse = bulkRequest.execute().actionGet(); 
if (bulkResponse.hasFailures()) { 
    // process failures by iterating through each bulk response item 
} 

我想索引各种商店的产品。每家商店都是不同的指数。当我到达包含大约60000种产品的第6店时,我得到了上述例外。我将大容量请求分成10000块,试图避免内存不足问题。 我不明白哪里是瓶颈。如果我以某种方式刷新批量请求或重新启动客户端,它会有帮助吗? 我看过类似的帖子,但没有为我工作。

编辑

当我米我每次处理一个新的批量请求时instantiting一个新的客户端,那么我没有得到内存溢出异常。但是,实例化一个新的客户端每次似乎不正确的..

谢谢

+0

导入的数据是什么样的? – 9000

+0

由于此错误发生在客户端,而不是实际的ES节点上,您可能只需要同时处理两个多产品。 – Bax

+0

@ 9000 - {“名称”:“无线形状鼠标”,“数量”:“100”,“制造”:“索尼”,“价格”:“23.73”}。这是一个产品线。 – panipsilos

回答

1

所以我想通了,什么是错误的。

每个新的批量请求都加到前一个,最终导致内存不足。

因此,现在我开始一个新的批量请求之前,我运行 bulkRequest = client.prepareBulk(); 刷新以前的请求。

谢谢大家的意见

相关问题