diff --git a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapper.java b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapper.java index 2afa9c5be5a05..6d779e64e797b 100644 --- a/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapper.java +++ b/modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapper.java @@ -394,11 +394,6 @@ public String typeName() { public String toString() { return super.toString() + ",prefixChars=" + minChars + ":" + maxChars; } - - @Override - public Query existsQuery(QueryShardContext context) { - throw new UnsupportedOperationException(); - } } static final class PrefixFieldMapper extends FieldMapper { diff --git a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapperTests.java b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapperTests.java index d476951e36034..fa331fee2efff 100644 --- a/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapperTests.java +++ b/modules/mapper-extras/src/test/java/org/elasticsearch/index/mapper/SearchAsYouTypeFieldMapperTests.java @@ -26,12 +26,14 @@ import org.apache.lucene.index.IndexableField; import org.apache.lucene.index.IndexableFieldType; import org.apache.lucene.index.Term; +import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.ConstantScoreQuery; import org.apache.lucene.search.DisjunctionMaxQuery; import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.MultiPhraseQuery; +import org.apache.lucene.search.NormsFieldExistsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.SynonymQuery; import org.apache.lucene.search.TermQuery; @@ -54,6 +56,7 @@ import org.elasticsearch.index.query.MatchPhraseQueryBuilder; import org.elasticsearch.index.query.MultiMatchQueryBuilder; import org.elasticsearch.index.query.QueryShardContext; +import org.elasticsearch.index.search.QueryStringQueryParser; import org.elasticsearch.plugins.Plugin; import java.io.IOException; @@ -532,6 +535,34 @@ public void testMatchPhrase() throws IOException { } } + public void testNestedExistsQuery() throws IOException, ParseException { + MapperService ms = createMapperService(mapping(b -> { + b.startObject("foo"); + { + b.field("type", "object"); + b.startObject("properties"); + { + b.startObject("bar"); + { + b.field("type", "search_as_you_type"); + } + b.endObject(); + } + b.endObject(); + } + b.endObject(); + })); + QueryShardContext qsc = createQueryShardContext(ms); + QueryStringQueryParser parser = new QueryStringQueryParser(qsc, "f"); + Query q = parser.parse("foo:*"); + assertEquals(new ConstantScoreQuery(new BooleanQuery.Builder() + .add(new NormsFieldExistsQuery("foo.bar"), BooleanClause.Occur.SHOULD) + .add(new NormsFieldExistsQuery("foo.bar._3gram"), BooleanClause.Occur.SHOULD) + .add(new NormsFieldExistsQuery("foo.bar._2gram"), BooleanClause.Occur.SHOULD) + .add(new TermQuery(new Term("_field_names", "foo.bar._index_prefix")), BooleanClause.Occur.SHOULD) + .build()), q); + } + private static BooleanQuery buildBoolPrefixQuery(String shingleFieldName, String prefixFieldName, List terms) { final BooleanQuery.Builder builder = new BooleanQuery.Builder(); for (int i = 0; i < terms.size() - 1; i++) { diff --git a/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperServiceTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperServiceTestCase.java index 19b66b2ee6e15..d8f4d15c9770f 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperServiceTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/mapper/MapperServiceTestCase.java @@ -392,6 +392,8 @@ protected QueryShardContext createQueryShardContext(MapperService mapperService) .thenAnswer(inv -> mapperService.fieldType(inv.getArguments()[0].toString()) != null); when(queryShardContext.getIndexAnalyzers()).thenReturn(mapperService.getIndexAnalyzers()); when(queryShardContext.getIndexSettings()).thenReturn(mapperService.getIndexSettings()); + when(queryShardContext.getObjectMapper(anyString())).thenAnswer( + inv -> mapperService.getObjectMapper(inv.getArguments()[0].toString())); when(queryShardContext.simpleMatchToIndexNames(anyObject())).thenAnswer( inv -> mapperService.simpleMatchToFullName(inv.getArguments()[0].toString()) );