Skip to content

Instantly share code, notes, and snippets.

@snellm
Created August 14, 2012 17:03
Show Gist options
  • Save snellm/3350884 to your computer and use it in GitHub Desktop.
Save snellm/3350884 to your computer and use it in GitHub Desktop.
Indexing document with same id within 60 seconds of delete causes VersionConflictEngineException
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;
import static org.elasticsearch.client.Requests.*;
import static org.elasticsearch.index.VersionType.*;
import static org.elasticsearch.node.NodeBuilder.*;
public class ElasticSearchGcDeletes {
private static final String INDEX = "foo";
private static final String TYPE = "bar";
private static final String ID = "12345";
private static final String SOURCE = "{\"key\": \"value\"}";
public static void main(String[] args) throws Exception {
System.out.println("Create a local node with index.gc_deletes set to zero seconds");
Settings settings = ImmutableSettings.settingsBuilder().put("index.gc_deletes", "0s").build();
Node node = nodeBuilder().settings(settings).local(true).node().start();
Client client = node.client();
System.out.println("Indexing a document with external versioning and a version of 2");
client.index(indexRequest(INDEX).type(TYPE).id(ID).versionType(EXTERNAL).version(2).source(SOURCE)).actionGet();
System.out.println("Deleting the document");
client.delete(deleteRequest(INDEX).type(TYPE).id(ID)).actionGet();
//System.out.println("Sleeping for one second");
//Thread.sleep(1000);
System.out.println("Indexing a document with external versioning and a version of 1");
client.index(indexRequest(INDEX).type(TYPE).id(ID).versionType(EXTERNAL).version(1).source(SOURCE)).actionGet();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment