Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/127991.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 127991
summary: Avoid nested docs in painless execute api
area: Infra/Scripting
type: bug
issues:
- 41004
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,8 @@ private static Response prepareRamIndex(
// This is a problem especially for indices that have no mappings, as no fields will be accessible, neither through doc
// nor _source (if there are no mappings there are no metadata fields).
ParsedDocument parsedDocument = documentMapper.parse(sourceToParse);
indexWriter.addDocuments(parsedDocument.docs());
// only index the root doc since nested docs are not supported in painless anyways
indexWriter.addDocuments(List.of(parsedDocument.rootDoc()));
try (IndexReader indexReader = DirectoryReader.open(indexWriter)) {
final IndexSearcher searcher = new IndexSearcher(indexReader);
searcher.setQueryCache(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ public void testDefaults() throws IOException {
assertThat(e.getCause().getMessage(), equalTo("cannot resolve symbol [doc]"));
}

public void testNestedDocs() throws IOException {
ScriptService scriptService = getInstanceFromNode(ScriptService.class);
IndexService indexService = createIndex("index", Settings.EMPTY, "doc", "rank", "type=long", "nested", "type=nested");

Request.ContextSetup contextSetup = new Request.ContextSetup("index", new BytesArray("""
{"rank": 4.0, "nested": [{"text": "foo"}, {"text": "bar"}]}"""), new MatchAllQueryBuilder());
contextSetup.setXContentType(XContentType.JSON);
Request request = new Request(new Script(ScriptType.INLINE, "painless", "doc['rank'].value", Map.of()), "score", contextSetup);
Response response = innerShardOperation(request, scriptService, indexService);
assertThat(response.getResult(), equalTo(4.0D));
}

public void testFilterExecutionContext() throws IOException {
ScriptService scriptService = getInstanceFromNode(ScriptService.class);
IndexService indexService = createIndex("index", Settings.EMPTY, "doc", "field", "type=long");
Expand Down
Loading