When I'm feeding a document with a long-value (Java API) and
retrieving the source of this doc back I'm getting an integer value.
What am I doing wrong? (See append code)
Kind Regards,
Peter.
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";
// load json from string
String fileAsString = "{"
+ ""tweet" : {"
+ " "properties" : {"
+ " "longval" : { "type" : "long",
"null_value" : -1}"
+ "}}}";
Client client = node.client();
// create index
CreateIndexResponse rsp = 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());//failed shards:0
Object num = response.getHits().hits()
[0].getSource().get("longval");
System.out.println("longval:" + num);//longval:124
System.out.println("longval.getClass:" + num.getClass());//
longval.getClass:class java.lang.Integer
node.stop();