Skip to content
Open
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 @@ -125,14 +125,18 @@ public class PercolatorFieldMapper extends ParametrizedFieldMapper {

@Override
public ParametrizedFieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName(), queryShardContext).init(this);
Builder builder = new Builder(simpleName(), queryShardContext);
builder.init(this);
builder.mapUnmappedFieldsAsText = mapUnmappedFieldsAsText;
return builder;
}

static class Builder extends ParametrizedFieldMapper.Builder {

private final Parameter<Map<String, String>> meta = Parameter.metaParam();

private final Supplier<QueryShardContext> queryShardContext;
private boolean mapUnmappedFieldsAsText;

Builder(String fieldName, Supplier<QueryShardContext> queryShardContext) {
super(fieldName);
Expand Down Expand Up @@ -178,7 +182,10 @@ public PercolatorFieldMapper build(BuilderContext context) {
);
}

private static boolean getMapUnmappedFieldAsText(Settings indexSettings) {
private boolean getMapUnmappedFieldAsText(Settings indexSettings) {
if (indexSettings.isEmpty()) {
return mapUnmappedFieldsAsText;
}
return INDEX_MAP_UNMAPPED_FIELDS_AS_TEXT_SETTING.get(indexSettings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.opensearch.index.query.QueryBuilder;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.query.QueryShardContext;
import org.opensearch.index.query.SimpleQueryStringBuilder;
import org.opensearch.plugins.Plugin;
import org.opensearch.script.MockScriptPlugin;
import org.opensearch.script.Script;
Expand Down Expand Up @@ -301,6 +302,53 @@ public void testMapUnmappedFieldAsText() throws IOException {
assertSearchHits(response, "1");
}

public void testMapUnmappedFieldAsTextAfterDynamicMappingUpdate() throws IOException {
Settings.Builder settings = Settings.builder().put("index.percolator.map_unmapped_fields_as_text", true);
IndexService indexService = createIndexWithSimpleMappings("test", settings.build(), "query", "type=percolator");

client().prepareIndex("test")
.setId("q1")
.setSource(
jsonBuilder().startObject()
.field("query", new SimpleQueryStringBuilder("test").field("unmapped_field_1").defaultOperator(Operator.AND))
.endObject()
)
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();

client().prepareIndex("test")
.setId("doc1")
.setSource(jsonBuilder().startObject().field("new_dynamic_field", "triggers dynamic mapping").endObject())
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();

PercolatorFieldMapper.PercolatorFieldType fieldType = (PercolatorFieldMapper.PercolatorFieldType) indexService.mapperService()
.fieldType("query");
assertTrue(fieldType.mapUnmappedFieldsAsText);

client().prepareIndex("test")
.setId("q2")
.setSource(
jsonBuilder().startObject()
.field("query", new SimpleQueryStringBuilder("test").field("unmapped_field_2").defaultOperator(Operator.AND))
.endObject()
)
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.get();

SearchResponse response = client().prepareSearch("test")
.setQuery(
new PercolateQueryBuilder(
"query",
BytesReference.bytes(jsonBuilder().startObject().field("unmapped_field_2", "test").endObject()),
MediaTypeRegistry.JSON
)
)
.get();
assertHitCount(response, 1);
assertSearchHits(response, "q2");
}

public void testRangeQueriesWithNow() throws Exception {
IndexService indexService = createIndexWithSimpleMappings(
"test",
Expand Down
Loading