将数据放入elasticsearch时如何在java api中使用“consistency”参数

时间:2016-08-08 11:08:40

标签: java elasticsearch

我在python程序中使用了“consistency”参数将数据成功地放到elasticsearch中,但我在java api中找不到“一致性”的用法。你能救我吗?

2 个答案:

答案 0 :(得分:0)

你可以写:

 client.prepareIndex("index", "doc", "doc1")
                .setSource("doc")
                .setConsistencyLevel(WriteConsistencyLevel.QUORUM)
                .execute()
                .actionGet()

答案 1 :(得分:0)

阅读以下链接: https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking_50_java_api_changes.html#_writeconsistencylevel_removed_on_write_requests

https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html#index-wait-for-active-shards

我认为您可以使用setWaitForActiveShards,它可以为所有分片副本获取最多为分片副本总数或ActiveShardCount.ALL的数值。