Finding out if an index exists

Hi
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(index.name())

is there a slightly more compact/simpler way to do this ?

Cheers
Z

We do this:

var establishedIndicies = ;

function initIndex(index) { if (establishedIndicies.contains(index)) {
return; } try {
getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();
} catch(e) { // Index does not exist yet.
getClient().admin().indices().create(createIndexRequest(index)).actionGet();
establishedIndicies.push(index); } }

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar zohar.melamed@gmail.com wrote:

Hi
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(
index.name())

is there a slightly more compact/simpler way to do this ?

Cheers
Z

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

The mail server must be slow. I just got your message now.

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar zohar.melamed@gmail.com wrote:

Hi
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(
index.name())

is there a slightly more compact/simpler way to do this ?

Cheers
Z

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

The cluster state is the way to do it (preferable over the index status
API). Use the builder API which is nicer (prepareState()).

On Tue, Nov 2, 2010 at 10:34 PM, James Cook jcook@tracermedia.com wrote:

We do this:

var establishedIndicies = ;

function initIndex(index) { if (establishedIndicies.contains(index)) {
return; } try {
getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();
} catch(e) { // Index does not exist yet.
getClient().admin().indices().create(createIndexRequest(index)).actionGet();
establishedIndicies.push(index); } }

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar zohar.melamed@gmail.com wrote:

Hi
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(
index.name())

is there a slightly more compact/simpler way to do this ?

Cheers
Z

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

I find that if I call this too soon after starting ES my index does not show
up. Is there any way to determine when the cluster is in a state where it
knows about the indices, even if it has not yet fully loaded them from a
gateway?

On Tue, Nov 2, 2010 at 2:20 PM, Shay Banon shay.banon@elasticsearch.comwrote:

The cluster state is the way to do it (preferable over the index status
API). Use the builder API which is nicer (prepareState()).

On Tue, Nov 2, 2010 at 10:34 PM, James Cook jcook@tracermedia.com wrote:

We do this:

var establishedIndicies = ;

function initIndex(index) { if (establishedIndicies.contains(index)) {
return; } try {
getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();
} catch(e) { // Index does not exist yet.
getClient().admin().indices().create(createIndexRequest(index)).actionGet();
establishedIndicies.push(index); } }

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar zohar.melamed@gmail.com wrote:

Hi
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(
index.name())

is there a slightly more compact/simpler way to do this ?

Cheers
Z

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

Paul Loy
paul@keteracel.com
http://uk.linkedin.com/in/paulloy

Use the cluster state API, its the first thing that gets recovered from the
gateway. While it has not recovered yet, its is in a blocked state, and you
can check that by using ClusterState#getBlocks() and verifying that there
are no global blocks.

Another option to wait for the cluster to recover is the use the cluster
health API, with all the different waitFor options. Waiting for a yellow
status on a specific index or across all indices.

-shay.banon

On Wed, Nov 3, 2010 at 1:23 AM, Paul Loy keteracel@gmail.com wrote:

I find that if I call this too soon after starting ES my index does not
show up. Is there any way to determine when the cluster is in a state where
it knows about the indices, even if it has not yet fully loaded them from a
gateway?

On Tue, Nov 2, 2010 at 2:20 PM, Shay Banon shay.banon@elasticsearch.comwrote:

The cluster state is the way to do it (preferable over the index status
API). Use the builder API which is nicer (prepareState()).

On Tue, Nov 2, 2010 at 10:34 PM, James Cook jcook@tracermedia.comwrote:

We do this:

var establishedIndicies = ;

function initIndex(index) { if (establishedIndicies.contains(index)) {
return; } try {
getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();
} catch(e) { // Index does not exist yet.
getClient().admin().indices().create(createIndexRequest(index)).actionGet();
establishedIndicies.push(index); } }

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar zohar.melamed@gmail.com wrote:

Hi
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(
index.name())

is there a slightly more compact/simpler way to do this ?

Cheers
Z

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-index-exists-tp1820921p1820921.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--

Paul Loy
paul@keteracel.com
Paul Loy - Amihan Entertainment | LinkedIn

Hi Shay,

I've stumbled across a problem with 0.12.1 and node.local=true when
checking for the existance of an index.
I'm using the sequence

client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
ClusterStateResponse response =
client.admin().cluster().prepareState().execute().actionGet();
boolean hasIndex =
response.getState().metaData().hasIndex(indexName);
if(!hasIndex)

client.admin().indices().create(createIndexRequest(indexName)).actionGet();

This works fine when I set discovery.zen.ping.unicast.hosts but fails
1 or 2 times out of 10 when setting
node.local=true. Then setWaitForYellowStatus() does not guarantee that
all indices are known and
the hasIndex() returns false although the index exists (and is visible
after a few more seconds).
Is this a known problem?

Kind regards
Christian

On Nov 2, 10:20 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

The cluster state is the way to do it (preferable over the index status
API). Use the builder API which is nicer (prepareState()).

On Tue, Nov 2, 2010 at 10:34 PM, James Cook jc...@tracermedia.com wrote:

We do this:

var establishedIndicies = ;

function initIndex(index) { if (establishedIndicies.contains(index)) {
return; } try {
getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();
} catch(e) { // Index does not exist yet.
getClient().admin().indices().create(createIndexRequest(index)).actionGet();
establishedIndicies.push(index); } }

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar zohar.mela...@gmail.com wrote:

Hi
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(
index.name())

is there a slightly more compact/simpler way to do this ?

Cheers
Z

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind...
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

We have the very same problem

This should be fixed in master (0.13), can you give it a go?

On Mon, Nov 15, 2010 at 6:47 PM, Christian Pesch cpesch@gmail.com wrote:

Hi Shay,

I've stumbled across a problem with 0.12.1 and node.local=true when
checking for the existance of an index.
I'm using the sequence

client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
ClusterStateResponse response =
client.admin().cluster().prepareState().execute().actionGet();
boolean hasIndex =
response.getState().metaData().hasIndex(indexName);
if(!hasIndex)

client.admin().indices().create(createIndexRequest(indexName)).actionGet();

This works fine when I set discovery.zen.ping.unicast.hosts but fails
1 or 2 times out of 10 when setting
node.local=true. Then setWaitForYellowStatus() does not guarantee that
all indices are known and
the hasIndex() returns false although the index exists (and is visible
after a few more seconds).
Is this a known problem?

Kind regards
Christian

On Nov 2, 10:20 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

The cluster state is the way to do it (preferable over the index status
API). Use the builder API which is nicer (prepareState()).

On Tue, Nov 2, 2010 at 10:34 PM, James Cook jc...@tracermedia.com
wrote:

We do this:

var establishedIndicies = ;

function initIndex(index) { if (establishedIndicies.contains(index)) {
return; } try {

getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();

} catch(e) { // Index does not exist yet.

getClient().admin().indices().create(createIndexRequest(index)).actionGet();

establishedIndicies.push(index); } }

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar zohar.mela...@gmail.com wrote:

Hi
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(

index.name())

is there a slightly more compact/simpler way to do this ?

Cheers
Z

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind.
..
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

Great! The error didn't occur on 15 startups, it seems to be gone.
Are you going to release 0.13.0 at the end of November?

On Nov 15, 5:57 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

This should be fixed in master (0.13), can you give it a go?

On Mon, Nov 15, 2010 at 6:47 PM, Christian Pesch cpe...@gmail.com wrote:

Hi Shay,

I've stumbled across a problem with 0.12.1 and node.local=true when
checking for the existance of an index.
I'm using the sequence

client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
ClusterStateResponse response =
client.admin().cluster().prepareState().execute().actionGet();
boolean hasIndex =
response.getState().metaData().hasIndex(indexName);
if(!hasIndex)

client.admin().indices().create(createIndexRequest(indexName)).actionGet();

This works fine when I set discovery.zen.ping.unicast.hosts but fails
1 or 2 times out of 10 when setting
node.local=true. Then setWaitForYellowStatus() does not guarantee that
all indices are known and
the hasIndex() returns false although the index exists (and is visible
after a few more seconds).
Is this a known problem?

Kind regards
Christian

On Nov 2, 10:20 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

The cluster state is the way to do it (preferable over the index status
API). Use the builder API which is nicer (prepareState()).

On Tue, Nov 2, 2010 at 10:34 PM, James Cook jc...@tracermedia.com
wrote:

We do this:

var establishedIndicies = ;

function initIndex(index) { if (establishedIndicies.contains(index)) {
return; } try {

getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();

} catch(e) { // Index does not exist yet.

getClient().admin().indices().create(createIndexRequest(index)).actionGet();

establishedIndicies.push(index); } }

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar zohar.mela...@gmail.com wrote:

Hi
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(

index.name())

is there a slightly more compact/simpler way to do this ?

Cheers
Z

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind.
..
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

0.13 will be released this week :), finalizing things now and running the
"long running" regression tests...

On Mon, Nov 15, 2010 at 7:27 PM, Christian Pesch cpesch@gmail.com wrote:

Great! The error didn't occur on 15 startups, it seems to be gone.
Are you going to release 0.13.0 at the end of November?

On Nov 15, 5:57 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

This should be fixed in master (0.13), can you give it a go?

On Mon, Nov 15, 2010 at 6:47 PM, Christian Pesch cpe...@gmail.com
wrote:

Hi Shay,

I've stumbled across a problem with 0.12.1 and node.local=true when
checking for the existance of an index.
I'm using the sequence

client.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

   ClusterStateResponse response =

client.admin().cluster().prepareState().execute().actionGet();
boolean hasIndex =
response.getState().metaData().hasIndex(indexName);
if(!hasIndex)

client.admin().indices().create(createIndexRequest(indexName)).actionGet();

This works fine when I set discovery.zen.ping.unicast.hosts but fails
1 or 2 times out of 10 when setting
node.local=true. Then setWaitForYellowStatus() does not guarantee that
all indices are known and
the hasIndex() returns false although the index exists (and is visible
after a few more seconds).
Is this a known problem?

Kind regards
Christian

On Nov 2, 10:20 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

The cluster state is the way to do it (preferable over the index
status
API). Use the builder API which is nicer (prepareState()).

On Tue, Nov 2, 2010 at 10:34 PM, James Cook jc...@tracermedia.com
wrote:

We do this:

var establishedIndicies = ;

function initIndex(index) { if
(establishedIndicies.contains(index)) {
return; } try {

getClient().admin().indices().status(indicesStatusRequest(index)).actionGet();

} catch(e) { // Index does not exist yet.

getClient().admin().indices().create(createIndexRequest(index)).actionGet();

establishedIndicies.push(index); } }

-- jim

On Mon, Nov 1, 2010 at 6:12 AM, zohar zohar.mela...@gmail.com
wrote:

Hi
We have some code to detect if an index exists :

client.admin().cluster().state(clusterStateRequest()).actionGet().getState().metaData().getIndices().containsKey(

index.name())

is there a slightly more compact/simpler way to do this ?

Cheers
Z

View this message in context:

http://elasticsearch-users.115913.n3.nabble.com/Finding-out-if-an-ind.

..

Sent from the Elasticsearch Users mailing list archive at
Nabble.com.