# Help needed in mapping

**URL:** <https://discuss.elastic.co/t/help-needed-in-mapping/8099>\
**Category:** Elasticsearch\
**Created:** [June 14, 2012, 6:34am UTC](https://discuss.elastic.co/t/help-needed-in-mapping/8099 "2012-06-14T06:34:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://discuss.elastic.co/u/Saurabh)\
**Post date:** [June 14, 2012, 6:34am UTC](https://discuss.elastic.co/t/help-needed-in-mapping/8099/1 "2012-06-14T06:34:14Z")

</div>

I am using the following code to map the index.

String indexType = "tweet";  
String fileAsString = "{"  
+ ""tweet" : {"  
+ " "properties" : {"  
+ " "message" : { "type" : "string", "null\_value" :  
"na"}"  
+ "}}}";  
BulkRequestBuilder bulkRequest = client.prepareBulk();

client.admin().indices().prepareCreate(indexName).addMapping(indexType,fileAsString).execute().actionGet();

```
    IndexRequestBuilder req = client.prepareIndex("twitter", "tweet")
            .setSource(jsonBuilder()
                    .startObject()
                        .field("user", "kimchy")
                        .field("postDate", "12 June")
                        .field("message", "trying out Elastic Search")
                    .endObject()
                  );
    bulkRequest.add(req);
    
    String s = null;
    bulkRequest.add(client.prepareIndex("twitter", "tweet")
            .setSource(jsonBuilder()
                        .startObject()
                            .field("user", "kimchy")
                            .field("postDate", "12 June")
                            .field("message", s)
                        .endObject()
                      )
            );

```

For the second record the message is null , in the index it should store  
its value as "na" , but instead it is storing null. Tell me where am i  
wrong?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [June 14, 2012, 6:44am UTC](https://discuss.elastic.co/t/help-needed-in-mapping/8099/2 "2012-06-14T06:44:32Z")

</div>

That's a common error.

You think that ES will modify your source and put NA instead of null.

No. Es will index NA but when you ask for document source, you get back the exact document you sent.

HTH  
David 😉  
Twitter : @dadoonet / @elasticsearchfr

Le 14 juin 2012 à 08:34, Saurabh [saurabh.k1510@gmail.com](mailto:saurabh.k1510@gmail.com) a écrit :

> I am using the following code to map the index.
> 
> String indexType = "tweet";  
> String fileAsString = "{"  
> + ""tweet" : {"  
> + " "properties" : {"  
> + " "message" : { "type" : "string", "null\_value" : "na"}"  
> + "}}}";  
> BulkRequestBuilder bulkRequest = client.prepareBulk();
> 
> ```
> client.admin().indices().prepareCreate(indexName).addMapping(indexType,fileAsString).execute().actionGet();
>    
> IndexRequestBuilder req = client.prepareIndex("twitter", "tweet")
> .setSource(jsonBuilder()
> .startObject()
> .field("user", "kimchy")
> .field("postDate", "12 June")
> .field("message", "trying out Elastic Search")
> .endObject()
> );
> bulkRequest.add(req);
>     
> String s = null;
> bulkRequest.add(client.prepareIndex("twitter", "tweet")
> .setSource(jsonBuilder()
> .startObject()
> .field("user", "kimchy")
> .field("postDate", "12 June")
> .field("message", s)
> .endObject()
> )
> );
> 
> ```
> 
> For the second record the message is null , in the index it should store its value as "na" , but instead it is storing null. Tell me where am i wrong?

---

<div class="post-metadata">

**Author:** ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://discuss.elastic.co/u/Saurabh)\
**Post date:** [June 14, 2012, 6:49am UTC](https://discuss.elastic.co/t/help-needed-in-mapping/8099/3 "2012-06-14T06:49:06Z")

</div>

That means if i search for message="na" i should get one hit, but instead  
i am getting 0 hits. Can you explain this?

On Thursday, 14 June 2012 12:14:32 UTC+5:30, David Pilato wrote:

> That's a common error.
> 
> You think that ES will modify your source and put NA instead of null.
> 
> No. Es will index NA but when you ask for document source, you get back  
> the exact document you sent.
> 
> HTH  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr
> 
> Le 14 juin 2012 à 08:34, Saurabh [saurabh.k1510@gmail.com](mailto:saurabh.k1510@gmail.com) a écrit :
> 
> > I am using the following code to map the index.
> > 
> > String indexType = "tweet";  
> > String fileAsString = "{"  
> > + ""tweet" : {"  
> > + " "properties" : {"  
> > + " "message" : { "type" : "string",  
> > "null\_value" : "na"}"  
> > + "}}}";  
> > BulkRequestBuilder bulkRequest = client.prepareBulk();
> 
> client.admin().indices().prepareCreate(indexName).addMapping(indexType,fileAsString).execute().actionGet();
> 
> > ```
> > IndexRequestBuilder req = client.prepareIndex("twitter", 
> > 
> > ```
> 
> "tweet")
> 
> > ```
> > .setSource(jsonBuilder() 
> > .startObject() 
> > .field("user", "kimchy") 
> > .field("postDate", "12 June") 
> > .field("message", "trying out Elastic 
> > 
> > ```
> 
> Search")
> 
> > ```
> > .endObject() 
> > ); 
> > bulkRequest.add(req); 
> >     
> > String s = null; 
> > bulkRequest.add(client.prepareIndex("twitter", "tweet") 
> > .setSource(jsonBuilder() 
> > .startObject() 
> > .field("user", "kimchy") 
> > .field("postDate", "12 June") 
> > .field("message", s) 
> > .endObject() 
> > ) 
> > ); 
> > 
> > ```
> > 
> > For the second record the message is null , in the index it should  
> > store its value as "na" , but instead it is storing null. Tell me where am  
> > i wrong?

---

<div class="post-metadata">

**Author:** ![Saurabh](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@Saurabh](https://discuss.elastic.co/u/Saurabh)\
**Post date:** [June 14, 2012, 7:15am UTC](https://discuss.elastic.co/t/help-needed-in-mapping/8099/4 "2012-06-14T07:15:33Z")

</div>

I was doing the search wrong. I got 1 hit. Thanks for the reply.

On Thursday, 14 June 2012 12:19:06 UTC+5:30, Saurabh wrote:

> That means if i search for message="na" i should get one hit, but instead  
> i am getting 0 hits. Can you explain this?
> 
> On Thursday, 14 June 2012 12:14:32 UTC+5:30, David Pilato wrote:
> 
> > That's a common error.
> > 
> > You think that ES will modify your source and put NA instead of null.
> > 
> > No. Es will index NA but when you ask for document source, you get back  
> > the exact document you sent.
> > 
> > HTH  
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr
> > 
> > Le 14 juin 2012 à 08:34, Saurabh [saurabh.k1510@gmail.com](mailto:saurabh.k1510@gmail.com) a écrit :
> > 
> > > I am using the following code to map the index.
> > > 
> > > String indexType = "tweet";  
> > > String fileAsString = "{"  
> > > + ""tweet" : {"  
> > > + " "properties" : {"  
> > > + " "message" : { "type" : "string",  
> > > "null\_value" : "na"}"  
> > > + "}}}";  
> > > BulkRequestBuilder bulkRequest = client.prepareBulk();
> > 
> > client.admin().indices().prepareCreate(indexName).addMapping(indexType,fileAsString).execute().actionGet();
> > 
> > > ```
> > > IndexRequestBuilder req = client.prepareIndex("twitter", 
> > > 
> > > ```
> > 
> > "tweet")
> > 
> > > ```
> > > .setSource(jsonBuilder() 
> > > .startObject() 
> > > .field("user", "kimchy") 
> > > .field("postDate", "12 June") 
> > > .field("message", "trying out Elastic 
> > > 
> > > ```
> > 
> > Search")
> > 
> > > ```
> > > .endObject() 
> > > ); 
> > > bulkRequest.add(req); 
> > >     
> > > String s = null; 
> > > bulkRequest.add(client.prepareIndex("twitter", "tweet") 
> > > .setSource(jsonBuilder() 
> > > .startObject() 
> > > .field("user", "kimchy") 
> > > .field("postDate", "12 June") 
> > > .field("message", s) 
> > > .endObject() 
> > > ) 
> > > ); 
> > > 
> > > ```
> > > 
> > > For the second record the message is null , in the index it should  
> > > store its value as "na" , but instead it is storing null. Tell me where am  
> > > i wrong?

---

<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:24am UTC](https://discuss.elastic.co/t/help-needed-in-mapping/8099/5 "2017-07-06T03:24:17Z")

</div>


