I have an index with a field chunks
with keyword
type which is just an a list of keyword. When I search through I do something like
{
"query": {
"bool": {
"filter": [
{
"term": {
"chunks": "chunk1"
}
},
{
"term": {
"chunks": "chunk2"
}
}
]
}
}
}
So I can retrieve all documents where there are both "chunk1" and "chunk2" inside the chunks field. However what if I care about the order? My solution is too have a script like
String[] chunks = doc['chunks'];
int c = 0;
String chunk = params.chunks[0];
for (int i = 0; i < chunks.length; ++i) {
if (chunk == chunks[i]) {
if (++c == params.chunks.length) {
return true;
}
chunk = params.chunks[c];
}
}
return false;
where params.chunks is something like ["chunk1", "chunk2"]
. The problem is the doc['chunks']
is unordered, while params._source
isn't allowed from _search
context.
It should be possible somehow, because Elastic itself has similar functionality for multitext search, so I can emulate the same field structure.