To move forward with my work I am catching IndexAlreadyExistsException and 
ignoring it.
But I think this is bug. 

Yes, this a actual code. 
Added complete java file. 

On Thursday, December 11, 2014 11:36:31 PM UTC-8, David Pilato wrote:
>
> Ha!
>
> TBH I prefer to do a try catch (IndexAlreadyExistsException) then testing 
> first.
> Will try to reproduce your case.
>
> Is it the actual code you are running?
>
> David
>
> Le 12 déc. 2014 à 08:32, Saurabh Saxena <[email protected] <javascript:>> 
> a écrit :
>
> Hi David,
>
> I made mistake while copying, it is actually 
>
> if(!res.isExists()) 
>
> - Saurabh
>
> On Thursday, December 11, 2014 10:09:11 PM UTC-8, David Pilato wrote:
>>
>> May be with:
>>
>> if(!res.isExists())
>>
>> :)
>>
>> David
>>
>> Le 12 déc. 2014 à 01:37, Saurabh Saxena <[email protected]> a écrit :
>>
>> I am using version v1.4.0.
>>
>> On Thursday, December 11, 2014 4:30:23 PM UTC-8, Saurabh Saxena wrote:
>>>
>>> Hi, 
>>>
>>> I am using the following java code to create instance of ElasticSearch 
>>> instance and create a index called "testindex".
>>>
>>> Node node = 
>>> NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder()
>>>                                                       .put("path.data", 
>>> "/etc/elasticsearch")
>>>                                                       .put("cluster.name", 
>>> "testcluster"))
>>>                                       .node();
>>> Client client = node.client();
>>> IndicesAdminClient indices = client.admin().indices();
>>> IndicesExistsResponse res = 
>>> indices.prepareExists("testindex").execute().actionGet();
>>> if(res.isExists()){ //Everytime getting value as false 
>>>   CreateIndexRequestBuilder createIndexRequestBuilder = 
>>> indices.prepareCreate("testindex");
>>>   createIndexRequestBuilder.execute().actionGet(); // Erring out with 
>>> IndexAlreadyExistsException
>>> }
>>>
>>> Before creating the index I am checking whether index exists or not, I 
>>> only create the index if it exists. 
>>> Second time when I am running the above code, it fails with 
>>> IndexAlreadyExistsException. 
>>> It seems like the IndicesExistsResponse.isExists() is not behaving 
>>> correctly. 
>>>
>>> Above code works fine if default elasticsearch.yml file is present in 
>>> the classpath. IndicesExistResponse.isExists() returns true if 
>>> elasticsearch.yml is in the classpath.
>>>
>>> Any workaround to resolve the issues ?
>>>
>>>
>>> Regards,
>>> Saurabh Saxena
>>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elasticsearch" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elasticsearch/38d97ae1-5df9-4c46-8cb5-e79f1d6c588d%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elasticsearch/38d97ae1-5df9-4c46-8cb5-e79f1d6c588d%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>  -- 
> You received this message because you are subscribed to the Google Groups 
> "elasticsearch" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elasticsearch/0f91ac48-e08a-47ff-9243-c69c5bffc470%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/elasticsearch/0f91ac48-e08a-47ff-9243-c69c5bffc470%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/142f5f24-5331-42b7-b426-1102a4663fc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;


public class ElasticSearchTest {

	public static void main(String[] args) {

		Node node = NodeBuilder.nodeBuilder().settings(ImmutableSettings.settingsBuilder()
				.put("path.data", "/etc/elasticsearch")
				.put("cluster.name", "testcluster"))
				.node();
		Client client = node.client();
		IndicesAdminClient indices = client.admin().indices();
		IndicesExistsResponse res = indices.prepareExists("testindex").execute().actionGet();
		if(!res.isExists()){ //Everytime getting value as false
			CreateIndexRequestBuilder createIndexRequestBuilder = indices.prepareCreate("testindex");
			System.out.println("Creating index");
			createIndexRequestBuilder.execute().actionGet(); // Erring out with IndexAlreadyExistsException
		}
	}

}

Reply via email to