Skip to content

Commit

Permalink
Fix UOE when fetching flattened field
Browse files Browse the repository at this point in the history
The new fields option allows to fetch the value of all fields in the mapping.
However, internal fields that are used by some field mappers are also shown when
concrete fields retrieved through a pattern (`*` or `foo*`).
We have a [long term plan](elastic#63446) to hide these fields in field_caps and from pattern resolution
so this change is just a hot fix to ensure that they don't break the retrieval in the meantime.
The `flattened._keyed field will show up as an empty field when using a pattern that match the
flattened field.

Relates elastic#63446
  • Loading branch information
jimczi committed Oct 27, 2020
1 parent eaac649 commit cf316ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public IndexFieldData.Builder fielddataBuilder(String fullyQualifiedIndexName, S

@Override
public ValueFetcher valueFetcher(MapperService mapperService, SearchLookup searchLookup, String format) {
throw new UnsupportedOperationException();
return lookup -> List.of();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import org.elasticsearch.index.mapper.FieldTypeTestCase;
import org.elasticsearch.xpack.flattened.mapper.FlattenedFieldMapper.KeyedFlattenedFieldType;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class KeyedFlattenedFieldTypeTests extends FieldTypeTestCase {

Expand Down Expand Up @@ -148,4 +150,12 @@ public void testWildcardQuery() {
() -> ft.wildcardQuery("valu*", null, false, randomMockShardContext()));
assertEquals("[wildcard] queries are not currently supported on keyed [flattened] fields.", e.getMessage());
}

public void testFetchIsEmpty() throws IOException {
Map<String, Object> sourceValue = Map.of("key", "value");
KeyedFlattenedFieldType ft = createFieldType();

assertEquals(List.of(), fetchSourceValue(ft, sourceValue));
assertEquals(List.of(), fetchSourceValue(ft, null));
}
}

0 comments on commit cf316ce

Please sign in to comment.