Skip to content

Commit

Permalink
Support dotted field names in counted_keyword (elastic#102283)
Browse files Browse the repository at this point in the history
With this commit we correctly handle dotted field names in the recently
introduced `counted_keyword` field type.

Relates elastic#101826
  • Loading branch information
danielmitterdorfer authored Nov 16, 2023
1 parent bd4f296 commit 68d7f88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public FieldMapper build(MapperBuilderContext context) {
name,
FIELD_TYPE,
new CountedKeywordFieldType(
name,
context.buildFullName(name),
true,
false,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@

package org.elasticsearch.xpack.countedkeyword;

import org.apache.lucene.index.IndexableField;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperTestCase;
import org.elasticsearch.index.mapper.ParsedDocument;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.xcontent.XContentBuilder;
import org.junit.AssumptionViolatedException;

import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class CountedKeywordFieldMapperTests extends MapperTestCase {
@Override
Expand Down Expand Up @@ -67,4 +71,15 @@ protected SyntheticSourceSupport syntheticSourceSupport(boolean ignoreMalformed)
protected IngestScriptSupport ingestScriptSupport() {
throw new AssumptionViolatedException("not supported");
}

public void testDottedFieldNames() throws IOException {
DocumentMapper mapper = createDocumentMapper(mapping(b -> {
b.startObject("dotted.field");
b.field("type", CountedKeywordFieldMapper.CONTENT_TYPE);
b.endObject();
}));
ParsedDocument doc = mapper.parse(source(b -> b.field("dotted.field", "1234")));
List<IndexableField> fields = doc.rootDoc().getFields("dotted.field");
assertEquals(1, fields.size());
}
}

0 comments on commit 68d7f88

Please sign in to comment.