Disable _source field store or enable compression for it


(Slava G ) #1

Hi,
I wanted to disable storing _source field and also to not make one of
the fields not analyzable, this is the code:
Client client = node.client();

		 XContentBuilder data = jsonBuilder().startObject()
         .startObject("properties")
                 .startObject("bdate")
                         .field("type", "string")
                         .field("index", "not_analyzed")
                         .field("store", "yes")
                 .endObject()
                 .startObject("_source")
                         .field("enabled", false)
                 .endObject()
                 .endObject()
         .endObject();


		client.admin().indices().create(new

CreateIndexRequest("test").mapping("cont", data));
IndexResponse indexRes = client.prepareIndex("test", "cont", "1")
.setSource(jsonBuilder()
.startObject()
.field("Name", "Test")
.field("BirthDate", new Date())
.field("Email", "test@test.com")
.field("bdate", "1234567890")
.endObject()
).execute()
.actionGet();

But, when I'm doing search - I still get the _source field , but on
the other hand - the not_analyzable field is indeed not participating
in
the search.
What could be my mistake here ?

Thank You and Best Regards.


(Shay Banon) #2

The _source needs to be on the same level as properties, not within it.

On Wednesday, June 1, 2011 at 11:20 PM, slavag wrote:

Hi,
I wanted to disable storing _source field and also to not make one of
the fields not analyzable, this is the code:
Client client = node.client();

XContentBuilder data = jsonBuilder().startObject()
.startObject("properties")
.startObject("bdate")
.field("type", "string")
.field("index", "not_analyzed")
.field("store", "yes")
.endObject()
.startObject("_source")
.field("enabled", false)
.endObject()
.endObject()
.endObject();

client.admin().indices().create(new
CreateIndexRequest("test").mapping("cont", data));
IndexResponse indexRes = client.prepareIndex("test", "cont", "1")
.setSource(jsonBuilder()
.startObject()
.field("Name", "Test")
.field("BirthDate", new Date())
.field("Email", "test@test.com (mailto:test@test.com)")
.field("bdate", "1234567890")
.endObject()
).execute()
.actionGet();

But, when I'm doing search - I still get the _source field , but on
the other hand - the not_analyzable field is indeed not participating
in
the search.
What could be my mistake here ?

Thank You and Best Regards.


(system) #3