# ElasticSearchIllegalArgumentException on native java script's doc() call

**URL:** <https://discuss.elastic.co/t/elasticsearchillegalargumentexception-on-native-java-scripts-doc-call/12669>\
**Category:** Elasticsearch\
**Created:** [July 4, 2013, 6:33pm UTC](https://discuss.elastic.co/t/elasticsearchillegalargumentexception-on-native-java-scripts-doc-call/12669 "2013-07-04T18:33:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oreno](https://avatars.discourse-cdn.com/v4/letter/o/b4bc9f/32.png) [@oreno](https://discuss.elastic.co/u/oreno)\
**Post date:** [July 4, 2013, 6:33pm UTC](https://discuss.elastic.co/t/elasticsearchillegalargumentexception-on-native-java-scripts-doc-call/12669/1 "2013-07-04T18:33:01Z")

</div>

Hi All,  
I was wandering if anyone could assist me with the following issue.

I have the next mapping:  
{  
"user": {  
"properties": {  
"name": {  
"type": "string"  
},  
"events": {  
"type": "nested",  
"include\_in\_parent": "true",  
"include\_in\_root": "true",  
"properties": {  
"event\_time": {  
"type": "Date"  
},  
"products": {  
"properties": {  
"product": {  
"type": "string"  
}  
}  
}  
}  
}  
}  
}  
}

and I'm trying to reach the 'events' array on the native java script, but getting the next error while executing  
return doc().get("events").getClass().toString():

error: SearchPhaseExecutionException[Failed to execute phase [query\_fetch], total failure; shardFailures {ElasticSearchIllegalArgumentException[No field found for [events] in mapping with types []]}]

my query is :  
curl -XPOST '[http://localhost:9200/users\_info/\_search](http://localhost:9200/users_info/_search)

{  
"query": {  
"nested": {  
"path": "events",  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"events.products.product": "2365443"  
}  
},  
{  
"range": {  
"events.event\_time": {  
"gte": "2013-05-1"  
}  
}  
},  
{  
"range": {  
"events.event\_time": {  
"lte": "2013-05-1"  
}  
}  
}  
]  
}  
}  
}  
},  
"script\_fields": {  
"MessageReverted": {  
"script": "revert",  
"lang": "native",  
"params": {  
"startDate": "2013-05-18"  
}  
}  
}  
}

I tried about anything but I can't retrieve anything from the doc() value.  
Any idea what I'm doing wrong? am I setting the include\_in\_parent/include\_in\_root correctly?

I'm able to get to the source().get("events") value though and retrieve all the data I actually need, but I think that it's too expensive on performance, and all the examples I saw used the doc() method so I guess that will be better.

can you please advise?

Thanks in advanced,

Oren

---

<div class="post-metadata">

**Author:** ![Maciej\_Kula](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Maciej\_Kula](https://discuss.elastic.co/u/Maciej_Kula)\
**Post date:** [July 5, 2013, 8:39am UTC](https://discuss.elastic.co/t/elasticsearchillegalargumentexception-on-native-java-scripts-doc-call/12669/2 "2013-07-05T08:39:19Z")

</div>

Hey Oren,

I have two guesses:

1. I don't think there will be an 'events' field: I think there will be a  
'events.event\_time' field (probably an array of Longs). I believe, when you  
have include\_in\_parent set to True, the nested documents are stored as  
arrays whose length is equal to the number of nested docs, and number is  
equal to the number of fields in the nested documents. Example:

{  
"user": {  
"properties": {  
"name": {  
"type": "string"  
},  
"events": {  
"type": "nested",  
"include\_in\_parent": "true",  
"include\_in\_root": "true",  
"properties": {  
"event\_time": {  
"type": "Date"  
},  
"event\_type":{  
"type": "string"  
}  
}  
}  
}  
}  
}  
}  
}

should give you two arrays in the user document, events.event\_time and  
events.event\_type --- and they will have length equal to the number of  
nested events documents. Consequently, you should use  
doc().get("events.event\_time").

1. I can see that you have a nested 'products' object in your events  
documents: I don't know how this will be treated. Perhaps try removing it  
and getting the event time using the method above?

Let me know if this helps!

On Thursday, July 4, 2013 7:33:01 PM UTC+1, Oreno wrote:

> Hi All,  
> I was wandering if anyone could assist me with the following issue.
> 
> I have the next mapping:  
> {  
> "user": {  
> "properties": {  
> "name": {  
> "type": "string"  
> },  
> "events": {  
> "type": "nested",  
> "include\_in\_parent": "true",  
> "include\_in\_root": "true",  
> "properties": {  
> "event\_time": {  
> "type": "Date"  
> },  
> "products": {  
> "properties": {  
> "product": {  
> "type": "string"  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> }
> 
> and I'm trying to reach the 'events' array on the native java script, but  
> getting the next error while executing  
> return doc().get("events").getClass().toString():
> 
> error: SearchPhaseExecutionException[Failed to execute phase  
> [query\_fetch],  
> total failure; shardFailures {ElasticSearchIllegalArgumentException[No  
> field  
> found for [events] in mapping with types ]}]
> 
> my query is :  
> curl -XPOST '[http://localhost:9200/users\_info/\_search](http://localhost:9200/users_info/_search)
> 
> {  
> "query": {  
> "nested": {  
> "path": "events",  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "events.products.product": "2365443"  
> }  
> },  
> {  
> "range": {  
> "events.event\_time": {  
> "gte": "2013-05-1"  
> }  
> }  
> },  
> {  
> "range": {  
> "events.event\_time": {  
> "lte": "2013-05-1"  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> },  
> "script\_fields": {  
> "MessageReverted": {  
> "script": "revert",  
> "lang": "native",  
> "params": {  
> "startDate": "2013-05-18"  
> }  
> }  
> }  
> }
> 
> I tried about anything but I can't retrieve anything from the doc() value.  
> Any idea what I'm doing wrong? am I setting the  
> include\_in\_parent/include\_in\_root correctly?
> 
> I'm able to get to the source().get("events") value though and retrieve  
> all  
> the data I actually need, but I think that it's too expensive on  
> performance, and all the examples I saw used the doc() method so I guess  
> that will be better.
> 
> can you please advise?
> 
> Thanks in advanced,
> 
> Oren
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/ElasticSearchIllegalArgumentException-on-native-java-script-s-doc-call-tp4037579.html](http://elasticsearch-users.115913.n3.nabble.com/ElasticSearchIllegalArgumentException-on-native-java-script-s-doc-call-tp4037579.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![oreno](https://avatars.discourse-cdn.com/v4/letter/o/b4bc9f/32.png) [@oreno](https://discuss.elastic.co/u/oreno)\
**Post date:** [July 5, 2013, 2:43pm UTC](https://discuss.elastic.co/t/elasticsearchillegalargumentexception-on-native-java-scripts-doc-call/12669/3 "2013-07-05T14:43:56Z")

</div>

Hi Maciej, i appreciate you help.  
I still haven't been able to reach the fields from the java native script.  
I was however able to reach those fields from mvel script by returning doc[events.event\_time].values and doc[products.product].values, I can't really execute my logic that way but I use it as a kind of reference. But I see a problem here that might be the same when using the java script. I'm getting the time\_event & the segment fields as arrays of the document but the connections between the two is being lost.  
I can't really tell which products are related to which event\_time that way. You know what I mean?

When using the source() I can go over the events and retrieve their exact related products. I'm afraid I wouldn't be able to achieve this using the doc().

Any idea?

---

<div class="post-metadata">

**Author:** ![Maciej\_Kula](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Maciej\_Kula](https://discuss.elastic.co/u/Maciej_Kula)\
**Post date:** [July 5, 2013, 2:59pm UTC](https://discuss.elastic.co/t/elasticsearchillegalargumentexception-on-native-java-scripts-doc-call/12669/4 "2013-07-05T14:59:14Z")

</div>

That's right --- you will get two arrays of equal length. You will have to  
walk them both, and retrieve elements from each at the same index to get  
the connections back (to get the first document, take the 0 element from  
one and the 0 element from the other and so on).

On Friday, July 5, 2013 3:43:57 PM UTC+1, Oreno wrote:

> Hi Maciej, i appreciate you help.  
> I still haven't been able to reach the fields from the java native  
> script.  
> I was however able to reach those fields from mvel script by returning  
> doc[events.event\_time].values and doc[products.product].values, I can't  
> really execute my logic that way but I use it as a kind of reference. But  
> I  
> see a problem here that might be the same when using the java script. I'm  
> getting the time\_event & the segment fields as arrays of the document but  
> the connections between the two is being lost.  
> I can't really tell which products are related to which event\_time that  
> way.  
> You know what I mean?
> 
> When using the source() I can go over the events and retrieve their exact  
> related products. I'm afraid I wouldn't be able to achieve this using the  
> doc().
> 
> Any idea?
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/ElasticSearchIllegalArgumentException-on-native-java-script-s-doc-call-tp4037579p4037610.html](http://elasticsearch-users.115913.n3.nabble.com/ElasticSearchIllegalArgumentException-on-native-java-script-s-doc-call-tp4037579p4037610.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![oreno](https://avatars.discourse-cdn.com/v4/letter/o/b4bc9f/32.png) [@oreno](https://discuss.elastic.co/u/oreno)\
**Post date:** [July 5, 2013, 3:14pm UTC](https://discuss.elastic.co/t/elasticsearchillegalargumentexception-on-native-java-scripts-doc-call/12669/5 "2013-07-05T15:14:15Z")

</div>

That will be a problem since there are different amount of products for different events.  
Accessing the data that way would not perform the logic I need(distinguishing between events by their product list).  
So I guess that leaves me with the source() ☹

Any idea how to improve the performance for that source() approach?

On 05.07.2013, at 18:00, "Maciej Kula [via Elasticsearch Users]" [ml-node+s115913n4037612h7@n3.nabble.com](mailto:ml-node+s115913n4037612h7@n3.nabble.com) wrote:

> That's right --- you will get two arrays of equal length. You will have to walk them both, and retrieve elements from each at the same index to get the connections back (to get the first document, take the 0 element from one and the 0 element from the other and so on).
> 
> On Friday, July 5, 2013 3:43:57 PM UTC+1, Oreno wrote:
> 
> > Hi Maciej, i appreciate you help.  
> > I still haven't been able to reach the fields from the java native script.  
> > I was however able to reach those fields from mvel script by returning  
> > doc[events.event\_time].values and doc[products.product].values, I can't  
> > really execute my logic that way but I use it as a kind of reference. But I  
> > see a problem here that might be the same when using the java script. I'm  
> > getting the time\_event & the segment fields as arrays of the document but  
> > the connections between the two is being lost.  
> > I can't really tell which products are related to which event\_time that way.  
> > You know what I mean?
> > 
> > When using the source() I can go over the events and retrieve their exact  
> > related products. I'm afraid I wouldn't be able to achieve this using the  
> > doc().
> > 
> > Any idea?
> > 
> > --  
> > View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/ElasticSearchIllegalArgumentException-on-native-java-script-s-doc-call-tp4037579p4037610.html](http://elasticsearch-users.115913.n3.nabble.com/ElasticSearchIllegalArgumentException-on-native-java-script-s-doc-call-tp4037579p4037610.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> 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 [hidden email].  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> If you reply to this email, your message will be added to the discussion below:  
> [http://elasticsearch-users.115913.n3.nabble.com/ElasticSearchIllegalArgumentException-on-native-java-script-s-doc-call-tp4037579p4037612.html](http://elasticsearch-users.115913.n3.nabble.com/ElasticSearchIllegalArgumentException-on-native-java-script-s-doc-call-tp4037579p4037612.html)  
> To unsubscribe from ElasticSearchIllegalArgumentException on native java script's doc() call, click here.  
> NAML

---

<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, 2:28am UTC](https://discuss.elastic.co/t/elasticsearchillegalargumentexception-on-native-java-scripts-doc-call/12669/6 "2017-07-06T02:28:00Z")

</div>


