Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public void resolveAsMergedMapping(

// public for testing only
public static IndexResolution mergedMappings(String indexPattern, FieldCapabilitiesResponse fieldCapsResponse) {
var numberOfIndices = fieldCapsResponse.getIndexResponses().size();
assert ThreadPool.assertCurrentThreadPool(ThreadPool.Names.SEARCH_COORDINATION); // too expensive to run this on a transport worker
if (fieldCapsResponse.getIndexResponses().isEmpty()) {
return IndexResolution.notFound(indexPattern);
Expand Down Expand Up @@ -143,8 +142,7 @@ public static IndexResolution mergedMappings(String indexPattern, FieldCapabilit
);
fields.put(name, field);

var isPartiallyUnmapped = fcs.size() < numberOfIndices;
if (isPartiallyUnmapped) {
if (fieldCapsResponse.getIndexResponses().stream().allMatch(fcir -> fcir.get().containsKey(fullName)) == false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this could be a bit expensive for many fields or many indices or both cases.
Lets check if this affects esql/from_idx_limit_1 benchmark after merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed the potential issue by instead of also taking into account the number of mapping hash duplicates.

partiallyUnmappedFields.add(fullName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse;
import org.elasticsearch.action.fieldcaps.IndexFieldCapabilities;
import org.elasticsearch.action.fieldcaps.IndexFieldCapabilitiesBuilder;
import org.elasticsearch.common.hash.MessageDigests;
import org.elasticsearch.common.lucene.BytesRefs;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexMode;
Expand Down Expand Up @@ -3101,6 +3102,27 @@ public void testResolveInsist_multiIndexFieldPartiallyExistsWithMultiTypesNoKeyw
assertThat(attr.unresolvedMessage(), is(expected));
}

public void testResolveInsist_multiIndexSameMapping_fieldIsMapped() {
assumeTrue("Requires UNMAPPED FIELDS", EsqlCapabilities.Cap.UNMAPPED_FIELDS.isEnabled());

IndexResolution resolution = IndexResolver.mergedMappings(
"foo, bar",
new FieldCapabilitiesResponse(
List.of(
fieldCapabilitiesIndexResponse("foo", messageResponseMap("long")),
fieldCapabilitiesIndexResponse("bar", messageResponseMap("long"))
),
List.of()
)
);
var plan = analyze("FROM foo, bar | INSIST_🐔 message", analyzer(resolution, TEST_VERIFIER));
var limit = as(plan, Limit.class);
var insist = as(limit.child(), Insist.class);
var attribute = (FieldAttribute) EsqlTestUtils.singleValue(insist.output());
assertThat(attribute.name(), is("message"));
assertThat(attribute.dataType(), is(DataType.LONG));
}

public void testResolveInsist_multiIndexFieldPartiallyExistsWithMultiTypesWithKeyword_createsAnInvalidMappedField() {
assumeTrue("Requires UNMAPPED FIELDS", EsqlCapabilities.Cap.UNMAPPED_FIELDS.isEnabled());

Expand Down Expand Up @@ -3531,7 +3553,8 @@ private static FieldCapabilitiesIndexResponse fieldCapabilitiesIndexResponse(
String indexName,
Map<String, IndexFieldCapabilities> fields
) {
return new FieldCapabilitiesIndexResponse(indexName, indexName, fields, false, IndexMode.STANDARD);
String indexMappingHash = new String(MessageDigests.sha256().digest(fields.toString().getBytes()));
return new FieldCapabilitiesIndexResponse(indexName, indexMappingHash, fields, false, IndexMode.STANDARD);
}

private static Map<String, IndexFieldCapabilities> messageResponseMap(String date) {
Expand Down