ElasticSearchIllegalArgumentException on native java script's doc() call

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

{
"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

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

{
"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
Sent from the Elasticsearch Users mailing list archive at 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.
For more options, visit https://groups.google.com/groups/opt_out.

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?

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
Sent from the Elasticsearch Users mailing list archive at 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.
For more options, visit https://groups.google.com/groups/opt_out.

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() :frowning:

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 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
Sent from the Elasticsearch Users mailing list archive at 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.

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
To unsubscribe from ElasticSearchIllegalArgumentException on native java script's doc() call, click here.
NAML