Skip to content

Commit

Permalink
Correctly serialize search-as-you-type analyzer (#65359)
Browse files Browse the repository at this point in the history
The search-as-you-type mapper was using an incorrect default analyzer when
creating its merge builder, which meant that a configured analyzer would not
be included in serialization.  This in turn resulted in the master node
getting an incorrect configuration, and search-as-you-type fields always
using a standard analyzer.

This has already been fixed via subsequent refactorings in 7.11 and master,
so this fix is for 7.10 only.

Resolves #65319
  • Loading branch information
romseygeek committed Nov 23, 2020
1 parent 866a6af commit dc6b059
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ public SpanQuery spanPrefixQuery(String value, SpanMultiTermQueryWrapper.SpanRew
private final PrefixFieldMapper prefixField;
private final ShingleFieldMapper[] shingleFields;

private final Builder builder;

public SearchAsYouTypeFieldMapper(String simpleName,
SearchAsYouTypeFieldType mappedFieldType,
CopyTo copyTo,
Expand All @@ -563,6 +565,7 @@ public SearchAsYouTypeFieldMapper(String simpleName,
this.store = builder.store.getValue();
this.indexOptions = builder.indexOptions.getValue();
this.termVectors = builder.termVectors.getValue();
this.builder = builder;
}

@Override
Expand All @@ -589,7 +592,7 @@ protected String contentType() {

@Override
public ParametrizedFieldMapper.Builder getMergeBuilder() {
return new Builder(simpleName(), () -> fieldType().indexAnalyzer()).init(this);
return new Builder(simpleName(), builder.analyzers.indexAnalyzer::getDefaultValue).init(this);
}

public static String getShingleFieldName(String parentField, int shingleSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.lucene.search.spans.FieldMaskingSpanQuery;
import org.apache.lucene.search.spans.SpanNearQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.lucene.search.MultiPhrasePrefixQuery;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.IndexSettings;
Expand Down Expand Up @@ -554,6 +555,20 @@ public void testMultiMatchBoolPrefix() throws IOException {
asList("quick brown fox jump", "brown fox jump lazy", "fox jump lazy dog"))));
}

public void testAnalyzerSerialization() throws IOException {
MapperService ms = createMapperService(fieldMapping(b -> {
b.field("type", "search_as_you_type");
b.field("analyzer", "simple");
}));
String serialized = Strings.toString(ms.documentMapper());
assertEquals(serialized,
"{\"_doc\":{\"properties\":{\"field\":" +
"{\"type\":\"search_as_you_type\",\"doc_values\":false,\"max_shingle_size\":3,\"analyzer\":\"simple\"}}}}");

merge(ms, mapping(b -> {}));
assertEquals(serialized, Strings.toString(ms.documentMapper()));
}

private void documentParsingTestCase(Collection<String> values) throws IOException {
DocumentMapper defaultMapper = createDocumentMapper(fieldMapping(this::minimalMapping));
final ParsedDocument parsedDocument = defaultMapper.parse(source(b -> {
Expand Down

0 comments on commit dc6b059

Please sign in to comment.