# How to store fields

**URL:** <https://discuss.elastic.co/t/how-to-store-fields/3773>\
**Category:** Elasticsearch\
**Created:** [January 13, 2011, 6:22pm UTC](https://discuss.elastic.co/t/how-to-store-fields/3773 "2011-01-13T18:22:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Algoncalves](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Algoncalves](https://discuss.elastic.co/u/Algoncalves)\
**Post date:** [January 13, 2011, 6:22pm UTC](https://discuss.elastic.co/t/how-to-store-fields/3773/1 "2011-01-13T18:22:54Z")

</div>

Hi All,

I´m new in the list and also in ElasticSearch. My doubt is basic, but  
I couldn´t find an answer in the documentation.

I´ve inslalled ES and the server is running. However when I indexed  
some document using Java API fields are not stored. How can I do this  
using Java API.

Thanks,

Alex

---

<div class="post-metadata">

**Author:** ![lowang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lowang/32/3284_2.png) [@lowang](https://discuss.elastic.co/u/lowang)\
**Post date:** [January 13, 2011, 8:56pm UTC](https://discuss.elastic.co/t/how-to-store-fields/3773/2 "2011-01-13T20:56:42Z")

</div>

did you use any mapping? what is the answer when you try to fetch the  
documents using curl ?

On Jan 13, 7:22 pm, Alex [alexandre.l.goncal...@gmail.com](mailto:alexandre.l.goncal...@gmail.com) wrote:

> Hi All,
> 
> I´m new in the list and also in Elasticsearch. My doubt is basic, but  
> I couldn´t find an answer in the documentation.
> 
> I´ve inslalled ES and the server is running. However when I indexed  
> some document using Java API fields are not stored. How can I do this  
> using Java API.
> 
> Thanks,
> 
> Alex

---

<div class="post-metadata">

**Author:** ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)\
**Post date:** [January 15, 2011, 8:47pm UTC](https://discuss.elastic.co/t/how-to-store-fields/3773/3 "2011-01-15T20:47:42Z")

</div>

try something like that:

Node node = nodeBuilder().  
local(true).  
settings(ImmutableSettings.settingsBuilder().  
put("number\_of\_shards", 3).  
put("number\_of\_replicas", 1).  
//put("gateway.type", "none").  
build()).  
build().  
start();

```
    String indexName = "tweetindex";
    String indexType = "tweet";

```

// put this under \_default/tweet.json or use it directly in java:  
String fileAsString = "{"  
+ ""tweet" : {"  
+ " "properties" : {"  
+ " "longval" : { "type" : "long",  
"null\_value" : -1}"  
+ "}}}";

```
    Client client = node.client();

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

```

CreateIndexRequest(indexName).mapping(indexType, fileAsString)).  
actionGet();  
client.admin().cluster().health(new  
ClusterHealthRequest(indexName).waitForYellowStatus()).actionGet();

```
    XContentBuilder docBuilder =

```

XContentFactory.jsonBuilder().startObject();  
docBuilder.field("longval", 124L);  
docBuilder.endObject();

```
    // feed previously created doc
    IndexRequestBuilder irb = client.prepareIndex(indexName,

```

indexType, "1").  
setConsistencyLevel(WriteConsistencyLevel.DEFAULT).  
setSource(docBuilder);  
irb.execute().actionGet();

```
    // make doc available for sure
    client.admin().indices().refresh(new

```

RefreshRequest(indexName)).actionGet();

```
    // query for this doc
    XContentQueryBuilder qb = QueryBuilders.matchAllQuery();
    TermFilterBuilder fb = FilterBuilders.termFilter("longval",

```

124L);  
SearchRequestBuilder srb = client.prepareSearch(indexName).  
setSearchType(SearchType.QUERY\_AND\_FETCH).  
setQuery(QueryBuilders.filteredQuery(qb, fb));  
SearchResponse response = srb.execute().actionGet();  
System.out.println("failed shards:" +  
response.getFailedShards());  
Object num = response.getHits().hits()  
[0].getSource().get("longval");  
System.out.println("longval:" + num);  
node.stop();

On 13 Jan., 19:22, Alex [alexandre.l.goncal...@gmail.com](mailto:alexandre.l.goncal...@gmail.com) wrote:

> Hi All,
> 
> I´m new in the list and also in Elasticsearch. My doubt is basic, but  
> I couldn´t find an answer in the documentation.
> 
> I´ve inslalled ES and the server is running. However when I indexed  
> some document using Java API fields are not stored. How can I do this  
> using Java API.
> 
> Thanks,
> 
> Alex

---

<div class="post-metadata">

**Author:** ![Algoncalves](https://avatars.discourse-cdn.com/v4/letter/a/ecd19e/32.png) [@Algoncalves](https://discuss.elastic.co/u/Algoncalves)\
**Post date:** [January 18, 2011, 1:55pm UTC](https://discuss.elastic.co/t/how-to-store-fields/3773/4 "2011-01-18T13:55:42Z")

</div>

It works. Meanwhile thanks. I´ll try to evolve my understanding about mapping.

Alex

---

<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, 4:13am UTC](https://discuss.elastic.co/t/how-to-store-fields/3773/5 "2017-07-06T04:13:37Z")

</div>


