Using java get document api within a script field


(mat) #1

Is it possible to query the database from a script field by instantiating a java client and issuing a get request?
Are there any examples of this?

Thanks
Mat

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/1d61260b-72e5-45de-bcfd-ffc74dacdc2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(mat) #2

Figured this out, however the code below seems to restart a new node on
each request, and is not cleaning up after itself.
Is there a better way to do this - for example by exposing a shared node
object to the mvel script plugin ?

PUT /test/user/1
{ "name":"jane"
, "partner":2
}

PUT /test/user/2
{ "name":"john"
, "partner":1
}

GET /test/user/_search
{ "_source":true
, "script_fields":
{ "partner":
{
"script":"org.elasticsearch.node.NodeBuilder.nodeBuilder().node().client().prepareGet('test',
'user',_source.partner).execute().actionGet().getSource()"
}
}
}

On Tuesday, April 1, 2014 4:44:40 PM UTC-7, mat taylor wrote:

Is it possible to query the database from a script field by instantiating
a java client and issuing a get request?
Are there any examples of this?

Thanks
Mat

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a0f57ffc-cecf-4bc8-8082-9f5737faea87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(David Pilato) #3

O_o starting a Node from a script? First time I see that... Looks like a hack to me! :slight_smile:

That said what is the use case here? Are you trying to perform some JOIN using scripts?

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 2 avr. 2014 à 05:46, mat taylor mat.taylor@gmail.com a écrit :

Figured this out, however the code below seems to restart a new node on each request, and is not cleaning up after itself.
Is there a better way to do this - for example by exposing a shared node object to the mvel script plugin ?

PUT /test/user/1
{ "name":"jane"
, "partner":2
}

PUT /test/user/2
{ "name":"john"
, "partner":1
}

GET /test/user/_search
{ "_source":true
, "script_fields":
{ "partner":
{ "script":"org.elasticsearch.node.NodeBuilder.nodeBuilder().node().client().prepareGet('test', 'user',_source.partner).execute().actionGet().getSource()"
}
}
}

On Tuesday, April 1, 2014 4:44:40 PM UTC-7, mat taylor wrote:
Is it possible to query the database from a script field by instantiating a java client and issuing a get request?
Are there any examples of this?
Thanks
Mat

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/a0f57ffc-cecf-4bc8-8082-9f5737faea87%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/0B3391C2-9F52-4B23-86F1-E4F7AA6FD2AB%40pilato.fr.
For more options, visit https://groups.google.com/d/optout.


(mat) #4

Yes. I wanted to join documents via a script, to avoid multiple round trips
to the client. Could be used to autoload parent docs from child docs for
example. I don't want to start a new node and client on each script call,
for obvious reasons. I suppose a native script plugin could do the trick
but I was wondering if there was any other way to invoke a shared node
client from a script which could be used accross multiple requests.

On Tuesday, April 1, 2014 9:46:17 PM UTC-7, David Pilato wrote:

O_o starting a Node from a script? First time I see that... Looks like a
hack to me! :slight_smile:

That said what is the use case here? Are you trying to perform some JOIN
using scripts?

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 2 avr. 2014 à 05:46, mat taylor <mat.t...@gmail.com <javascript:>> a
écrit :

Figured this out, however the code below seems to restart a new node on
each request, and is not cleaning up after itself.
Is there a better way to do this - for example by exposing a shared node
object to the mvel script plugin ?

PUT /test/user/1
{ "name":"jane"
, "partner":2
}

PUT /test/user/2
{ "name":"john"
, "partner":1
}

GET /test/user/_search
{ "_source":true
, "script_fields":
{ "partner":
{
"script":"org.elasticsearch.node.NodeBuilder.nodeBuilder().node().client().prepareGet('test',
'user',_source.partner).execute().actionGet().getSource()"
}
}
}

On Tuesday, April 1, 2014 4:44:40 PM UTC-7, mat taylor wrote:

Is it possible to query the database from a script field by instantiating
a java client and issuing a get request?
Are there any examples of this?

Thanks
Mat

--
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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/a0f57ffc-cecf-4bc8-8082-9f5737faea87%40googlegroups.comhttps://groups.google.com/d/msgid/elasticsearch/a0f57ffc-cecf-4bc8-8082-9f5737faea87%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/37072cd6-2c0a-4476-936a-23848c92c868%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(Jörg Prante) #5

I wrote a denormalizer plugin where I use a node client from a field
analyzer for a field type "deref". A node client is started as a singleton
per node where the plugin is installed. It can ask other indexes/types for
a doc by given ID for injecting additional terms from an array of terms of
the referenced doc into the current tokenizer stream.

It is not well tested and early in development, but I can share the code if
there is interest.

I would never start a client node from a a script, because of the enormous
overhead, as you have experienced.

Jörg

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEYBU64spM4QvtRSQDVxjMK7-yRENWC%2BqFhr4mkTHN49w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


(mat) #6

Yes that would be very interesting.
I have also got a good workaround to my issue now by using the lookup
script from https://github.com/imotov/elasticsearch-native-script-example

On Wednesday, April 2, 2014 1:17:52 AM UTC-7, Jörg Prante wrote:

I wrote a denormalizer plugin where I use a node client from a field
analyzer for a field type "deref". A node client is started as a singleton
per node where the plugin is installed. It can ask other indexes/types for
a doc by given ID for injecting additional terms from an array of terms of
the referenced doc into the current tokenizer stream.

It is not well tested and early in development, but I can share the code
if there is interest.

I would never start a client node from a a script, because of the enormous
overhead, as you have experienced.

Jörg

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/29da35bf-44e1-4fbf-85b6-2253f6943cbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #7