# Indexing fields without storing using Java API

**URL:** <https://discuss.elastic.co/t/indexing-fields-without-storing-using-java-api/9332>\
**Category:** Elasticsearch\
**Created:** [October 12, 2012, 3:22am UTC](https://discuss.elastic.co/t/indexing-fields-without-storing-using-java-api/9332 "2012-10-12T03:22:37Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dean\_2](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@dean\_2](https://discuss.elastic.co/u/dean_2)\
**Post date:** [October 12, 2012, 3:22am UTC](https://discuss.elastic.co/t/indexing-fields-without-storing-using-java-api/9332/1 "2012-10-12T03:22:37Z")

</div>

I want to just index all of the fields without storing them.  
How?

bulkRequest.add(client.prepareIndex("sponge2", "153299", "_ID_")  
.setSource(jsonBuilder()  
.startObject()  
.field("hostname", hostName2)  
.field("logtype", logType2)  
.field("env", env2)  
.field("logpath", logPath2)  
.field("logfilename", logFileName2)  
.field("timestamp", timeStamp)  
.field("eventbody", sCurrentLine)  
.endObject()  
)  
);  
I want "hostname","logtype","env","logpath","logfilename","timestamp"  
and "eventbody" indexed but not stored.  
And later I use these field as filters just get the "_ID_".

--

---

<div class="post-metadata">

**Author:** ![dean\_2](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@dean\_2](https://discuss.elastic.co/u/dean_2)\
**Post date:** [October 12, 2012, 3:45am UTC](https://discuss.elastic.co/t/indexing-fields-without-storing-using-java-api/9332/2 "2012-10-12T03:45:22Z")

</div>

Acutally, it may not be necessary to use "source".  
I just want to index all the fields and later I search them with a  
unique ID.  
I'm new to search. Maybe it's stupid question.

On 10月12日, 上午11时22分, dean [elasticbet...@gmail.com](mailto:elasticbet...@gmail.com) wrote:

> I want to just index all of the fields without storing them.  
> How?
> 
> bulkRequest.add(client.prepareIndex("sponge2", "153299", "_ID_")  
> .setSource(jsonBuilder()  
> .startObject()  
> .field("hostname", hostName2)  
> .field("logtype", logType2)  
> .field("env", env2)  
> .field("logpath", logPath2)  
> .field("logfilename", logFileName2)  
> .field("timestamp", timeStamp)  
> .field("eventbody", sCurrentLine)  
> .endObject()  
> )  
> );  
> I want "hostname","logtype","env","logpath","logfilename","timestamp"  
> and "eventbody" indexed but not stored.  
> And later I use these field as filters just get the "_ID_".

--

---

<div class="post-metadata">

**Author:** ![dean\_2](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@dean\_2](https://discuss.elastic.co/u/dean_2)\
**Post date:** [October 12, 2012, 3:48am UTC](https://discuss.elastic.co/t/indexing-fields-without-storing-using-java-api/9332/3 "2012-10-12T03:48:22Z")

</div>

I'm new to search. Maybe it's a stupid question.  
Actually, I want all the fields indexed to be searchable later.  
Then I just get the id by filtering those fields.  
Maybe "_ID_" is not nessary because I see there is a setID method.  
What's the differences?

On 10月12日, 上午11时22分, dean [elasticbet...@gmail.com](mailto:elasticbet...@gmail.com) wrote:

> I want to just index all of the fields without storing them.  
> How?
> 
> bulkRequest.add(client.prepareIndex("sponge2", "153299", "_ID_")  
> .setSource(jsonBuilder()  
> .startObject()  
> .field("hostname", hostName2)  
> .field("logtype", logType2)  
> .field("env", env2)  
> .field("logpath", logPath2)  
> .field("logfilename", logFileName2)  
> .field("timestamp", timeStamp)  
> .field("eventbody", sCurrentLine)  
> .endObject()  
> )  
> );  
> I want "hostname","logtype","env","logpath","logfilename","timestamp"  
> and "eventbody" indexed but not stored.  
> And later I use these field as filters just get the "_ID_".

--

---

<div class="post-metadata">

**Author:** ![Chris\_Male](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_male/32/2607_2.png) [@Chris\_Male](https://discuss.elastic.co/u/Chris_Male)\
**Post date:** [October 12, 2012, 4:08am UTC](https://discuss.elastic.co/t/indexing-fields-without-storing-using-java-api/9332/4 "2012-10-12T04:08:51Z")

</div>

Dean,

You're going to need to define a mapping for your fields, setting stored to  
false on those fields you dont want stored.. See

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

and [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/core-types.html) for  
some details.

On Friday, October 12, 2012 4:22:39 PM UTC+13, dean wrote:

> I want to just index all of the fields without storing them.  
> How?
> 
> bulkRequest.add(client.prepareIndex("sponge2", "153299", "_ID_")  
> .setSource(jsonBuilder()  
> .startObject()  
> .field("hostname",  
> hostName2)  
> .field("logtype",  
> logType2)  
> .field("env",  
> env2)  
> .field("logpath",  
> logPath2)
> 
> .field("logfilename", logFileName2)
> 
> .field("timestamp", timeStamp)
> 
> .field("eventbody", sCurrentLine)  
> .endObject()  
> )  
> );  
> I want "hostname","logtype","env","logpath","logfilename","timestamp"  
> and "eventbody" indexed but not stored.  
> And later I use these field as filters just get the "_ID_".

--

---

<div class="post-metadata">

**Author:** ![pounraj\_manikandan](https://avatars.discourse-cdn.com/v4/letter/p/9de0a6/32.png) [@pounraj\_manikandan](https://discuss.elastic.co/u/pounraj_manikandan)\
**Post date:** [October 12, 2012, 7:09am UTC](https://discuss.elastic.co/t/indexing-fields-without-storing-using-java-api/9332/5 "2012-10-12T07:09:34Z")

</div>

You are already there in building the data for a document, similar to that you have to build mappings as informed by Chris Male.

You can do that as below: (make sure index is already created before executing this request, and \_source field is disabled as below.)  
XContentBuilder **data** = XContentFactory.jsonBuilder().startObject()  
.startObject("settings")  
.startObject(" **\_source**")  
.field**("enabled", false)**  
.endObject()  
.startObject("properties")  
.startObject("content0")  
.field("type", "string")  
.endObject()  
.startObject("content1")  
.field("type", "string")  
.field**("store", "no")**  
.endObject()  
.endObject().endObject()  
.endObject();

```
		PutMappingRequest putMappingRequest = new PutMappingRequest(
				"dean_index");
		putMappingRequest.type("dean_type");
		putMappingRequest.source(<b>data</b>);
		PutMappingResponse putMappingResponse = client.admin().indices()
				.putMapping(putMappingRequest).actionGet();
		putMappingResponse.acknowledged();

```

FYI. By default Elasticsearch **doesn't store**.

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [October 12, 2012, 8:11am UTC](https://discuss.elastic.co/t/indexing-fields-without-storing-using-java-api/9332/6 "2012-10-12T08:11:18Z")

</div>

Hey,

by default only \_source is stored, other fields are not stored by default.  
so in your case you can simply set "\_source" : {"store" : false} via the  
mapping API when you create the index. here are some more details:

source  
field: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/source-field.html)  
create index with  
mapping: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html)  
(see the mapping part here)

simon

On Friday, October 12, 2012 6:08:51 AM UTC+2, Chris Male wrote:

> Dean,
> 
> You're going to need to define a mapping for your fields, setting stored  
> to false on those fields you dont want stored.. See  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html)  
> and [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/core-types.html) for  
> some details.
> 
> On Friday, October 12, 2012 4:22:39 PM UTC+13, dean wrote:
> 
> > I want to just index all of the fields without storing them.  
> > How?
> > 
> > bulkRequest.add(client.prepareIndex("sponge2", "153299", "_ID_")  
> > .setSource(jsonBuilder()  
> > .startObject()
> > 
> > .field("hostname", hostName2)  
> > .field("logtype",  
> > logType2)  
> > .field("env",  
> > env2)  
> > .field("logpath",  
> > logPath2)
> > 
> > .field("logfilename", logFileName2)
> > 
> > .field("timestamp", timeStamp)
> > 
> > .field("eventbody", sCurrentLine)  
> > .endObject()  
> > )  
> > );  
> > I want "hostname","logtype","env","logpath","logfilename","timestamp"  
> > and "eventbody" indexed but not stored.  
> > And later I use these field as filters just get the "_ID_".

--

---

<div class="post-metadata">

**Author:** ![dean\_2](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@dean\_2](https://discuss.elastic.co/u/dean_2)\
**Post date:** [October 15, 2012, 9:18am UTC](https://discuss.elastic.co/t/indexing-fields-without-storing-using-java-api/9332/7 "2012-10-15T09:18:36Z")

</div>

Thank all you guys.  
Your help is very valuable to me.  
Pounraj's source is just what I want.

在 2012年10月12日星期五UTC+8下午3时09分34秒，Manikandan Pounraj写道：

> You are already there in building the data for a document, similar to that  
> you have to build mappings as informed by Chris Male.
> 
> You can do that as below: (make sure index is already created before  
> executing this request, and \_source field is disabled as below.)  
> XContentBuilder _data =  
> XContentFactory.jsonBuilder().startObject()  
> .startObject("settings")  
> .startObject("\_source_")  
> .field\*("enabled", false)\*  
> .endObject()  
> .startObject("properties")  
> .startObject("content0")  
> .field("type", "string")  
> .endObject()  
> .startObject("content1")  
> .field("type", "string")  
> .field\*("store", "no")\*  
> .endObject()  
> .endObject().endObject()  
> .endObject();
> 
> ```
> PutMappingRequest putMappingRequest = new 
> 
> ```
> 
> PutMappingRequest(  
> "dean\_index");  
> putMappingRequest.type("dean\_type");  
> putMappingRequest.source(_data_);  
> PutMappingResponse putMappingResponse =  
> client.admin().indices()  
> .putMapping(putMappingRequest).actionGet();
> 
> ```
> putMappingResponse.acknowledged(); 
> 
> ```
> 
> FYI. By default Elasticsearch _doesn't store_.
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Indexing-fields-without-storing-using-Java-API-tp4023858p4023868.html](http://elasticsearch-users.115913.n3.nabble.com/Indexing-fields-without-storing-using-Java-API-tp4023858p4023868.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:08am UTC](https://discuss.elastic.co/t/indexing-fields-without-storing-using-java-api/9332/8 "2017-07-06T03:08:51Z")

</div>


