Java API to disable source


(thinusp) #1

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!


(Ivan Brusic) #2

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant settings.

--
Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo
thinus.prinsloo@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!


(thinusp) #3

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a
bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();
... (code to add documents to the builder)
response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =
client.admin().indices().prepareUpdateSettings(index);
usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :
false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I
get any sort of error to indicate so. I'd like to know, also, since
I'm loading quite a few documents, would it not make sense to make
this part of the bulk-request? In other words don't store the data to
begin with. What I'm thinking of is something more towards the
Field.Store.NO property (of Lucene) that I can set for every field
separately. I'd like to do this programmatically as well, i.e. not
with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant settings.

--
Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!


(Ivan Brusic) #4

Actually, I might be wrong since since the _source setting is not an
index setting, but a mapping property. In addition, I am not sure if
it is even possible to change the _source on a live index (never tried
to).

Next step would be to look into the PutMappingRequest. Sorry if I was
not too helpful.

--
Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo
thinus.prinsloo@gmail.com wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a
bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();
... (code to add documents to the builder)
response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =
client.admin().indices().prepareUpdateSettings(index);
usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :
false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I
get any sort of error to indicate so. I'd like to know, also, since
I'm loading quite a few documents, would it not make sense to make
this part of the bulk-request? In other words don't store the data to
begin with. What I'm thinking of is something more towards the
Field.Store.NO property (of Lucene) that I can set for every field
separately. I'd like to do this programmatically as well, i.e. not
with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant settings.

--
Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!


(Shay Banon) #5

Yea, update settings is for settings, not mappings. The best way to configure it is to set the relevant mapping when you create the index. You can have a mapping type called default to apply it to all mappings in that index. Moreoever, you can create an index template that matches on all indices (a template of *), with default mapping that disables source. This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an
index setting, but a mapping property. In addition, I am not sure if
it is even possible to change the _source on a live index (never tried
to).

Next step would be to look into the PutMappingRequest. Sorry if I was
not too helpful.

--
Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo
<thinus.prinsloo@gmail.com (mailto:thinus.prinsloo@gmail.com)> wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a
bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();
... (code to add documents to the builder)
response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =
client.admin().indices().prepareUpdateSettings(index);
usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :
false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I
get any sort of error to indicate so. I'd like to know, also, since
I'm loading quite a few documents, would it not make sense to make
this part of the bulk-request? In other words don't store the data to
begin with. What I'm thinking of is something more towards the
Field.Store.NO property (of Lucene) that I can set for every field
separately. I'd like to do this programmatically as well, i.e. not
with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic <i...@brusic.com (http://brusic.com)> wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant settings.

--
Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

<thinus.prins...@gmail.com (http://gmail.com)> wrote:

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!


(thinusp) #6

Shay,

Thank you, that seemed to do the trick. It's not pretty, imho, but it
works. I "create" the index first, using JSON and setting _source
enabled to false, then from there on I load the data fields in the
usual way. It would be nice if there was some option in the API
itself to disable the source, but for now this will do.

Thanks for the support Ivan and Shay!

On Feb 12, 4:45 pm, Shay Banon kim...@gmail.com wrote:

Yea, update settings is for settings, not mappings. The best way to configure it is to set the relevant mapping when you create the index. You can have a mapping type called default to apply it to all mappings in that index. Moreoever, you can create an index template that matches on all indices (a template of *), with default mapping that disables source. This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an
index setting, but a mapping property. In addition, I am not sure if
it is even possible to change the _source on a live index (never tried
to).

Next step would be to look into the PutMappingRequest. Sorry if I was
not too helpful.

--
Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo
<thinus.prins...@gmail.com (mailto:thinus.prins...@gmail.com)> wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a
bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();
... (code to add documents to the builder)
response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =
client.admin().indices().prepareUpdateSettings(index);
usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :
false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I
get any sort of error to indicate so. I'd like to know, also, since
I'm loading quite a few documents, would it not make sense to make
this part of the bulk-request? In other words don't store the data to
begin with. What I'm thinking of is something more towards the
Field.Store.NO property (of Lucene) that I can set for every field
separately. I'd like to do this programmatically as well, i.e. not
with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic <i...@brusic.com (http://brusic.com)> wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant settings.

--
Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

<thinus.prins...@gmail.com (http://gmail.com)> wrote:

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!


(Shay Banon) #7

Not sure I agree that being able to disable the source on the API level is better…, the mappings allows for one time worry free option if source is stored or not.

On Monday, February 13, 2012 at 9:50 AM, Thinus Prinsloo wrote:

Shay,

Thank you, that seemed to do the trick. It's not pretty, imho, but it
works. I "create" the index first, using JSON and setting _source
enabled to false, then from there on I load the data fields in the
usual way. It would be nice if there was some option in the API
itself to disable the source, but for now this will do.

Thanks for the support Ivan and Shay!

On Feb 12, 4:45 pm, Shay Banon <kim...@gmail.com (http://gmail.com)> wrote:

Yea, update settings is for settings, not mappings. The best way to configure it is to set the relevant mapping when you create the index. You can have a mapping type called default to apply it to all mappings in that index. Moreoever, you can create an index template that matches on all indices (a template of *), with default mapping that disables source. This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an
index setting, but a mapping property. In addition, I am not sure if
it is even possible to change the _source on a live index (never tried
to).

Next step would be to look into the PutMappingRequest. Sorry if I was
not too helpful.

--
Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo
<thinus.prins...@gmail.com (mailto:thinus.prins...@gmail.com (http://gmail.com))> wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a
bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();
... (code to add documents to the builder)
response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =
client.admin().indices().prepareUpdateSettings(index);
usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :
false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I
get any sort of error to indicate so. I'd like to know, also, since
I'm loading quite a few documents, would it not make sense to make
this part of the bulk-request? In other words don't store the data to
begin with. What I'm thinking of is something more towards the
Field.Store.NO property (of Lucene) that I can set for every field
separately. I'd like to do this programmatically as well, i.e. not
with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic <i...@brusic.com (http://brusic.com)> wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant settings.

--
Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

<thinus.prins...@gmail.com (http://gmail.com)> wrote:

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!


(thinusp) #8

Shay,

I actually agree with you. I suppose what would be nice is to have
the option to construct the table (say during the PrepareBulkRequest
process) and in this stage, once as you point out, set the mapping to
false. But I agree, since you create a table once and then populate
it with fields, this option should not be with the field itself.

On Feb 13, 8:29 pm, Shay Banon kim...@gmail.com wrote:

Not sure I agree that being able to disable the source on the API level is better…, the mappings allows for one time worry free option if source is stored or not.

On Monday, February 13, 2012 at 9:50 AM, Thinus Prinsloo wrote:

Shay,

Thank you, that seemed to do the trick. It's not pretty, imho, but it
works. I "create" the index first, using JSON and setting _source
enabled to false, then from there on I load the data fields in the
usual way. It would be nice if there was some option in the API
itself to disable the source, but for now this will do.

Thanks for the support Ivan and Shay!

On Feb 12, 4:45 pm, Shay Banon <kim...@gmail.com (http://gmail.com)> wrote:

Yea, update settings is for settings, not mappings. The best way to configure it is to set the relevant mapping when you create the index. You can have a mapping type called default to apply it to all mappings in that index. Moreoever, you can create an index template that matches on all indices (a template of *), with default mapping that disables source. This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an
index setting, but a mapping property. In addition, I am not sure if
it is even possible to change the _source on a live index (never tried
to).

Next step would be to look into the PutMappingRequest. Sorry if I was
not too helpful.

--
Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo
<thinus.prins...@gmail.com (mailto:thinus.prins...@gmail.com (http://gmail.com))> wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a
bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();
... (code to add documents to the builder)
response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =
client.admin().indices().prepareUpdateSettings(index);
usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :
false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I
get any sort of error to indicate so. I'd like to know, also, since
I'm loading quite a few documents, would it not make sense to make
this part of the bulk-request? In other words don't store the data to
begin with. What I'm thinking of is something more towards the
Field.Store.NO property (of Lucene) that I can set for every field
separately. I'd like to do this programmatically as well, i.e. not
with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic <i...@brusic.com (http://brusic.com)> wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant settings.

--
Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

<thinus.prins...@gmail.com (http://gmail.com)> wrote:

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!


(elfreyshira) #9

kimchy,

Thanks for the responding to Thinus. I also have the same question as
Thinus: how do I disable the _source through Java.

I would like an answer with more details please. Where and how would I set
this default mapping? Can you provide some sample code?

I am quite new to the elasticsearch world (about two days, actually), so
I'd appreciate the help!

Thanks,
Elfrey

On Sunday, February 12, 2012 8:45:28 AM UTC-6, kimchy wrote:

Yea, update settings is for settings, not mappings. The best way to
configure it is to set the relevant mapping when you create the index. You
can have a mapping type called default to apply it to all mappings in
that index. Moreoever, you can create an index template that matches on all
indices (a template of *), with default mapping that disables source.
This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an
index setting, but a mapping property. In addition, I am not sure if
it is even possible to change the _source on a live index (never tried
to).

Next step would be to look into the PutMappingRequest. Sorry if I was
not too helpful.

--
Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo
thinus.prinsloo@gmail.com wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a
bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();
... (code to add documents to the builder)
response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =
client.admin().indices().prepareUpdateSettings(index);
usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :
false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I
get any sort of error to indicate so. I'd like to know, also, since
I'm loading quite a few documents, would it not make sense to make
this part of the bulk-request? In other words don't store the data to
begin with. What I'm thinking of is something more towards the
Field.Store.NO property (of Lucene) that I can set for every field
separately. I'd like to do this programmatically as well, i.e. not
with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant
settings.

--
Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!

On Sunday, February 12, 2012 8:45:28 AM UTC-6, kimchy wrote:

Yea, update settings is for settings, not mappings. The best way to
configure it is to set the relevant mapping when you create the index. You
can have a mapping type called default to apply it to all mappings in
that index. Moreoever, you can create an index template that matches on all
indices (a template of *), with default mapping that disables source.
This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an
index setting, but a mapping property. In addition, I am not sure if
it is even possible to change the _source on a live index (never tried
to).

Next step would be to look into the PutMappingRequest. Sorry if I was
not too helpful.

--
Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo
thinus.prinsloo@gmail.com wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a
bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();
... (code to add documents to the builder)
response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =
client.admin().indices().prepareUpdateSettings(index);
usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :
false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I
get any sort of error to indicate so. I'd like to know, also, since
I'm loading quite a few documents, would it not make sense to make
this part of the bulk-request? In other words don't store the data to
begin with. What I'm thinking of is something more towards the
Field.Store.NO property (of Lucene) that I can set for every field
separately. I'd like to do this programmatically as well, i.e. not
with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant
settings.

--
Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!

On Sunday, February 12, 2012 8:45:28 AM UTC-6, kimchy wrote:

Yea, update settings is for settings, not mappings. The best way to
configure it is to set the relevant mapping when you create the index. You
can have a mapping type called default to apply it to all mappings in
that index. Moreoever, you can create an index template that matches on all
indices (a template of *), with default mapping that disables source.
This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an
index setting, but a mapping property. In addition, I am not sure if
it is even possible to change the _source on a live index (never tried
to).

Next step would be to look into the PutMappingRequest. Sorry if I was
not too helpful.

--
Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo
thinus.prinsloo@gmail.com wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a
bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();
... (code to add documents to the builder)
response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =
client.admin().indices().prepareUpdateSettings(index);
usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :
false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I
get any sort of error to indicate so. I'd like to know, also, since
I'm loading quite a few documents, would it not make sense to make
this part of the bulk-request? In other words don't store the data to
begin with. What I'm thinking of is something more towards the
Field.Store.NO property (of Lucene) that I can set for every field
separately. I'd like to do this programmatically as well, i.e. not
with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant
settings.

--
Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it
through the Java API. I believe the method to do it with JSON would
be to use the "_source" : {"enabled" : false} idea with the field, but
I do not know how to do this with the API. Thank you!


(David Pilato) #10

Hi Elfrey,

You probably could write something like:

   XContentBuilder xb = jsonBuilder()

         .startObject()

                .startObject("mytype")

                       .field("_source", "disabled")

                       .startObject("properties")

                              .startObject("myfield").field("type", "string").endObject()

                       .endObject()

                .endObject()

         .endObject();



         

   PutMappingRequestBuilder pmrb = client.admin().indices()

         .preparePutMapping("myindex")

         .setType("mytype").setSource(xb).execute().actionGet();                   

Hope this helps

David.

De : elasticsearch@googlegroups.com [mailto:elasticsearch@googlegroups.com] De la part de elfreyshira
Envoyé : lundi 23 juillet 2012 20:27
À : elasticsearch@googlegroups.com
Objet : Re: Java API to disable source

kimchy,

Thanks for the responding to Thinus. I also have the same question as Thinus: how do I disable the _source through Java.

I would like an answer with more details please. Where and how would I set this default mapping? Can you provide some sample code?

I am quite new to the elasticsearch world (about two days, actually), so I'd appreciate the help!

Thanks,

Elfrey

On Sunday, February 12, 2012 8:45:28 AM UTC-6, kimchy wrote:

Yea, update settings is for settings, not mappings. The best way to configure it is to set the relevant mapping when you create the index. You can have a mapping type called default to apply it to all mappings in that index. Moreoever, you can create an index template that matches on all indices (a template of *), with default mapping that disables source. This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an

index setting, but a mapping property. In addition, I am not sure if

it is even possible to change the _source on a live index (never tried

to).

Next step would be to look into the PutMappingRequest. Sorry if I was

not too helpful.

--

Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo

thinus.prinsloo@gmail.com wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a

bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();

... (code to add documents to the builder)

response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =

client.admin().indices().prepareUpdateSettings(index);

usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :

false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I

get any sort of error to indicate so. I'd like to know, also, since

I'm loading quite a few documents, would it not make sense to make

this part of the bulk-request? In other words don't store the data to

begin with. What I'm thinking of is something more towards the

Field.Store.NO property (of Lucene) that I can set for every field

separately. I'd like to do this programmatically as well, i.e. not

with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant settings.

--

Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it

through the Java API. I believe the method to do it with JSON would

be to use the "_source" : {"enabled" : false} idea with the field, but

I do not know how to do this with the API. Thank you!

On Sunday, February 12, 2012 8:45:28 AM UTC-6, kimchy wrote:

Yea, update settings is for settings, not mappings. The best way to configure it is to set the relevant mapping when you create the index. You can have a mapping type called default to apply it to all mappings in that index. Moreoever, you can create an index template that matches on all indices (a template of *), with default mapping that disables source. This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an

index setting, but a mapping property. In addition, I am not sure if

it is even possible to change the _source on a live index (never tried

to).

Next step would be to look into the PutMappingRequest. Sorry if I was

not too helpful.

--

Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo

thinus.prinsloo@gmail.com wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a

bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();

... (code to add documents to the builder)

response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =

client.admin().indices().prepareUpdateSettings(index);

usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :

false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I

get any sort of error to indicate so. I'd like to know, also, since

I'm loading quite a few documents, would it not make sense to make

this part of the bulk-request? In other words don't store the data to

begin with. What I'm thinking of is something more towards the

Field.Store.NO property (of Lucene) that I can set for every field

separately. I'd like to do this programmatically as well, i.e. not

with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant settings.

--

Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it

through the Java API. I believe the method to do it with JSON would

be to use the "_source" : {"enabled" : false} idea with the field, but

I do not know how to do this with the API. Thank you!

On Sunday, February 12, 2012 8:45:28 AM UTC-6, kimchy wrote:

Yea, update settings is for settings, not mappings. The best way to configure it is to set the relevant mapping when you create the index. You can have a mapping type called default to apply it to all mappings in that index. Moreoever, you can create an index template that matches on all indices (a template of *), with default mapping that disables source. This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an

index setting, but a mapping property. In addition, I am not sure if

it is even possible to change the _source on a live index (never tried

to).

Next step would be to look into the PutMappingRequest. Sorry if I was

not too helpful.

--

Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo

thinus.prinsloo@gmail.com wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a

bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();

... (code to add documents to the builder)

response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =

client.admin().indices().prepareUpdateSettings(index);

usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :

false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I

get any sort of error to indicate so. I'd like to know, also, since

I'm loading quite a few documents, would it not make sense to make

this part of the bulk-request? In other words don't store the data to

begin with. What I'm thinking of is something more towards the

Field.Store.NO property (of Lucene) that I can set for every field

separately. I'd like to do this programmatically as well, i.e. not

with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant settings.

--

Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it

through the Java API. I believe the method to do it with JSON would

be to use the "_source" : {"enabled" : false} idea with the field, but

I do not know how to do this with the API. Thank you!


(Igor Motov) #11

Hi Elfrey,

Here is a slightly modified version of David's example for disabling source
that you might want to try:

    XContentBuilder xb = jsonBuilder()
        .startObject()
            .startObject("mytype")
            .startObject("_source").field("enabled", false).endObject()
            .startObject("properties")
                .startObject("myfield").field("type", 

"string").endObject()
.endObject()
.endObject()
.endObject();

    PutMappingResponse pmrb = client.admin().indices()
            .preparePutMapping("myindex")
            .setType("mytype").setSource(xb).execute().actionGet();

In general, take a look at elasticsearch integration testshttps://github.com/elasticsearch/elasticsearch/blob/master/src/test/java/org/elasticsearch/test/unit/index/mapper/source/DefaultSourceMappingTests.java.
That's a great source of information about usage of Java API.

Igor

On Monday, July 23, 2012 3:27:23 PM UTC-4, David Pilato wrote:

Hi Elfrey,

You probably could write something like:

   XContentBuilder xb = *jsonBuilder*()

         .startObject()

                .startObject("mytype")

                       .field("_source", "disabled")

                       .startObject("properties")

                              .startObject("myfield").field("type", 

"string").endObject()

                       .endObject()

                .endObject()

         .endObject();



         

   PutMappingRequestBuilder pmrb = client.admin().indices()

         .preparePutMapping("myindex")

         .setType("mytype").setSource(xb).execute().actionGet();                   

Hope this helps

David.

De : elasticsearch@googlegroups.com [mailto:
elasticsearch@googlegroups.com] De la part de elfreyshira
Envoyé : lundi 23 juillet 2012 20:27
À : elasticsearch@googlegroups.com
Objet : Re: Java API to disable source

kimchy,

Thanks for the responding to Thinus. I also have the same question as
Thinus: how do I disable the _source through Java.

I would like an answer with more details please. Where and how would I set
this default mapping? Can you provide some sample code?

I am quite new to the elasticsearch world (about two days, actually), so
I'd appreciate the help!

Thanks,

Elfrey

On Sunday, February 12, 2012 8:45:28 AM UTC-6, kimchy wrote:

Yea, update settings is for settings, not mappings. The best way to
configure it is to set the relevant mapping when you create the index. You
can have a mapping type called default to apply it to all mappings in
that index. Moreoever, you can create an index template that matches on all
indices (a template of *), with default mapping that disables source.
This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an

index setting, but a mapping property. In addition, I am not sure if

it is even possible to change the _source on a live index (never tried

to).

Next step would be to look into the PutMappingRequest. Sorry if I was

not too helpful.

--

Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo

thinus.prinsloo@gmail.com wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a

bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();

... (code to add documents to the builder)

response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =

client.admin().indices().prepareUpdateSettings(index);

usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :

false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I

get any sort of error to indicate so. I'd like to know, also, since

I'm loading quite a few documents, would it not make sense to make

this part of the bulk-request? In other words don't store the data to

begin with. What I'm thinking of is something more towards the

Field.Store.NO property (of Lucene) that I can set for every field

separately. I'd like to do this programmatically as well, i.e. not

with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant
settings.

--

Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it

through the Java API. I believe the method to do it with JSON would

be to use the "_source" : {"enabled" : false} idea with the field, but

I do not know how to do this with the API. Thank you!

On Sunday, February 12, 2012 8:45:28 AM UTC-6, kimchy wrote:

Yea, update settings is for settings, not mappings. The best way to
configure it is to set the relevant mapping when you create the index. You
can have a mapping type called default to apply it to all mappings in
that index. Moreoever, you can create an index template that matches on all
indices (a template of *), with default mapping that disables source.
This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an

index setting, but a mapping property. In addition, I am not sure if

it is even possible to change the _source on a live index (never tried

to).

Next step would be to look into the PutMappingRequest. Sorry if I was

not too helpful.

--

Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo

thinus.prinsloo@gmail.com wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a

bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();

... (code to add documents to the builder)

response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =

client.admin().indices().prepareUpdateSettings(index);

usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :

false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I

get any sort of error to indicate so. I'd like to know, also, since

I'm loading quite a few documents, would it not make sense to make

this part of the bulk-request? In other words don't store the data to

begin with. What I'm thinking of is something more towards the

Field.Store.NO property (of Lucene) that I can set for every field

separately. I'd like to do this programmatically as well, i.e. not

with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant
settings.

--

Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it

through the Java API. I believe the method to do it with JSON would

be to use the "_source" : {"enabled" : false} idea with the field, but

I do not know how to do this with the API. Thank you!

On Sunday, February 12, 2012 8:45:28 AM UTC-6, kimchy wrote:

Yea, update settings is for settings, not mappings. The best way to
configure it is to set the relevant mapping when you create the index. You
can have a mapping type called default to apply it to all mappings in
that index. Moreoever, you can create an index template that matches on all
indices (a template of *), with default mapping that disables source.
This will disable source on all indices created in the cluster.

On Friday, February 10, 2012 at 8:14 PM, Ivan Brusic wrote:

Actually, I might be wrong since since the _source setting is not an

index setting, but a mapping property. In addition, I am not sure if

it is even possible to change the _source on a live index (never tried

to).

Next step would be to look into the PutMappingRequest. Sorry if I was

not too helpful.

--

Ivan

On Fri, Feb 10, 2012 at 12:03 AM, Thinus Prinsloo

thinus.prinsloo@gmail.com wrote:

Ivan, thanks!

Please could you help me a little bit more. The concepts here are a

bit complicated.

This is what I have:

BulkRequestBuilder builder = tClient.prepareBulk();

... (code to add documents to the builder)

response = builder.execute().actionGet();

UpdateSettingsRequestBuilder usrb =

client.admin().indices().prepareUpdateSettings(index);

usrb.setSettings( " { "theindex" : { "_source" : {"enabled" :

false} } } "); <-- Problem?

usrb.execute().actionGet();

The marked line is where I think things are going wrong, not that I

get any sort of error to indicate so. I'd like to know, also, since

I'm loading quite a few documents, would it not make sense to make

this part of the bulk-request? In other words don't store the data to

begin with. What I'm thinking of is something more towards the

Field.Store.NO property (of Lucene) that I can set for every field

separately. I'd like to do this programmatically as well, i.e. not

with JSON commands if I don't have to.

Thanks for the effort.

On Feb 9, 11:31 pm, Ivan Brusic i...@brusic.com wrote:

Hi Thinus,

Try using updateSettings on the IndicesAdminClient with the relevant
settings.

--

Ivan

On Thu, Feb 9, 2012 at 8:38 AM, Thinus Prinsloo

thinus.prins...@gmail.com wrote:

I would like to disable saving the source with the indexes, but do it

through the Java API. I believe the method to do it with JSON would

be to use the "_source" : {"enabled" : false} idea with the field, but

I do not know how to do this with the API. Thank you!


(elfreyshira) #12

David and Igor,

Thank you very much for your help. Once I've prepared the putmapping, what do I do with the pmrb variable? I want to index a new item after disabling the source.

I've posted my question in more detail here: http://elasticsearch-users.115913.n3.nabble.com/I-want-to-disable-the-source-with-Java-API-for-a-pre-existing-index-before-setting-a-new-ID-tc4020786.html

Again, thank you for your help!

  • Elfrey

(Igor Motov) #13

There is not much to do with pmrb. You can make sure that your request
was acknowledge by checking pmrb.acknowledged() is true, but that's pretty
much it. But after the putMapping call you can go ahead and index your
record.

On Tuesday, July 24, 2012 6:57:22 PM UTC-4, elfreyshira wrote:

David and Igor,

Thank you very much for your help. Once I've prepared the putmapping, what
do I do with the /pmrb/ variable? I want to index a new item after
disabling
the source.

I've posted my question in more detail here:

http://elasticsearch-users.115913.n3.nabble.com/I-want-to-disable-the-source-with-Java-API-for-a-pre-existing-index-before-setting-a-new-ID-tc4020786.html

http://elasticsearch-users.115913.n3.nabble.com/I-want-to-disable-the-source-with-Java-API-for-a-pre-existing-index-before-setting-a-new-ID-tc4020786.html

Again, thank you for your help!

  • Elfrey

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Java-API-to-disable-source-tp3730001p4020795.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(system) #14