Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure to apply eager_global_ordinals for keyed JSON fields. #41319

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.elasticsearch.index.mapper;

import org.elasticsearch.common.collect.CopyOnWriteHashMap;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.regex.Regex;

import java.util.Collection;
Expand Down Expand Up @@ -204,7 +205,16 @@ public Collection<String> simpleMatchToFullName(String pattern) {

@Override
public Iterator<MappedFieldType> iterator() {
return fullNameToFieldType.values().iterator();
Iterator<MappedFieldType> concreteFieldTypes = fullNameToFieldType.values().iterator();

if (fullNameToJsonMapper.isEmpty()) {
return concreteFieldTypes;
} else {
Iterator<MappedFieldType> keyedJsonFieldTypes = fullNameToJsonMapper.values().stream()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A note for future reference: the other option would have been to expose the field type by adding a 'keyed' field mapper in JsonFieldMapper#iterator. I didn't go down that path because this would make my_json_field._keyed a valid field to search on, which we want to avoid.

.<MappedFieldType>map(mapper -> mapper.keyedFieldType(""))
.iterator();
return Iterators.concat(concreteFieldTypes, keyedJsonFieldTypes);
}
}

// Visible for testing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import static java.util.Collections.emptyList;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.instanceOf;

public class FieldTypeLookupTests extends ESTestCase {
Expand Down Expand Up @@ -245,6 +248,22 @@ public void testSimpleMatchToFullName() {
assertTrue(names.contains("barometer"));
}

public void testFieldTypeIterator() {
MockFieldMapper mapper = new MockFieldMapper("foo");
JsonFieldMapper jsonMapper = createJsonMapper("object1.object2.field");

FieldTypeLookup lookup = new FieldTypeLookup()
.copyAndAddAll("type", newList(mapper, jsonMapper), emptyList());

Set<String> fieldNames = new HashSet<>();
for (MappedFieldType fieldType : lookup) {
fieldNames.add(fieldType.name());
}

assertThat(fieldNames, containsInAnyOrder(
mapper.name(), jsonMapper.name(), jsonMapper.keyedFieldName()));
}

public void testIteratorImmutable() {
MockFieldMapper f1 = new MockFieldMapper("foo");
FieldTypeLookup lookup = new FieldTypeLookup();
Expand Down