Using Painless Scripted Field

I have some question about using scripted field with painless, so i have some set of data that look like this,
One Document can only contain identifier (MWStart or MWEnd), and i want to get like:
if the identifier is MWStart then find the reqtxnid that the identifier is MWEnd. so how can i do dis?

and i have tried this script:

string reqTXNID = doc['reqtxnid.keyword'].value;
string idf = doc['identifier.keyword'].value;

if(idf == 'MWStart') {
for(int i=0; i<params._source.reqtxnid.length; i++) {
if(params._source.reqtxnid[i] == reqTXNID && params._source.identifier[i] == "MWEnd"){
return 1;
break;
}
else { return 0;}
}
}
else {return null;}

then i got this error:

Discover: compile error [script] Too many dynamic script compilations within one minute, max: [15/min]; please use on-disk, indexed, or scripts with parameters instead; this limit can be changed by the [script.max_compilations_per_minute] setting

i hope someone can help me :sob: , thanks

sorry if the previous script is unclear, this is the repost for the script:

qwe

and the result that i wanted should be look like this:

A scripted field only has access to a single document at a time. You seem to be under the mistaken impression that you can access the entire result set. There isn't a way to do what you are trying to do at query time. You may want to index the data so that each document contains both the start and end data.

Hope this helps.

Cheers
Rashmi

Oh i see rashmi, thanks. But then how can i index the data that can contains both start and end data while the source contain only one data? i really cant think the way to achieve this

You could create "entity-centric" indices. This page might help https://www.elastic.co/videos/entity-centric-indexing-mark-harwood

Thanks
Rashmi

oke ill try it rashmi, thanks!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.