# How to figure out field type?

**URL:** <https://discuss.elastic.co/t/how-to-figure-out-field-type/18726>\
**Category:** Elasticsearch\
**Created:** [July 17, 2014, 9:15pm UTC](https://discuss.elastic.co/t/how-to-figure-out-field-type/18726 "2014-07-17T21:15:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_M](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@Adrian\_M](https://discuss.elastic.co/u/Adrian_M)\
**Post date:** [July 17, 2014, 9:15pm UTC](https://discuss.elastic.co/t/how-to-figure-out-field-type/18726/1 "2014-07-17T21:15:08Z")

</div>

I've added some data to my ES.

JSON format:

{  
"doc":{  
"site" : "[marriage.com](http://marriage.com)",  
"name" : "amount-active-users",

"daily" : {  
"dataX": [1,2,3],  
"dataY": [1388538061, 1388624461, 1388710861],  
"startDate":1388538061,  
"endDate":1388710861  
}

}  
}

If you look at dataX field, it's an array. ES interprets it as an array on  
Longs.

Now when I add another JSON doc with dataX being doubles I'm not sure on  
the Java side how to know when the input is in format  
criptDocValues.Doubles or criptDocValues.Longs  
I would like data to be interpreted as doubles all the time.

This is the terrible code I use to case but it's not working after adding  
the doubles to the dataX field:

List dataXTimeSeries2Long= ((ScriptDocValues.Doubles)  
doc().get(rootPathDataX)).getValues();  
List dataXTimeSeries2 = new ArrayList();  
//reverse TS so that it matches order of series retrieved via  
client() - ya those are reversed  
for(int i=dataXTimeSeries2Long.size()-1; i\>-1; i--){

dataXTimeSeries2.add(Double.parseDouble(dataXTimeSeries2Long.get(i).toString()));  
//using toStr is slow  
}

This code fails with a class cast exception:  
ClassCastException[org.elasticsearch.index.fielddata.ScriptDocValues$Longs  
cannot be cast to  
org.elasticsearch.index.fielddata.ScriptDocValues$Doubles]; }]  
I can do that in Scala. Java is behind.

Help!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/12d62f00-b0c5-4552-b4fe-07a874085ce4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/12d62f00-b0c5-4552-b4fe-07a874085ce4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:15am UTC](https://discuss.elastic.co/t/how-to-figure-out-field-type/18726/2 "2017-07-06T01:15:06Z")

</div>


