Saurabh
(Saurabh)
June 14, 2012, 6:34am
1
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?
dadoonet
(David Pilato)
June 14, 2012, 6:44am
2
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 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?
Saurabh
(Saurabh)
June 14, 2012, 6:49am
3
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 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?
Saurabh
(Saurabh)
June 14, 2012, 7:15am
4
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 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?