Fixed quote_field_suffix in query_string (#29332)
This change fixes the handling of the `quote_field_suffix` option on `query_string` query. The expansion was not applied to default fields query. Closes #29324
This commit is contained in:
parent
08abbdf129
commit
644e5ea97a
|
@ -66,6 +66,7 @@ import static org.elasticsearch.common.lucene.search.Queries.fixNegativeQueryIfN
|
|||
import static org.elasticsearch.common.lucene.search.Queries.newLenientFieldQuery;
|
||||
import static org.elasticsearch.common.lucene.search.Queries.newUnmappedFieldQuery;
|
||||
import static org.elasticsearch.index.search.QueryParserHelper.resolveMappingField;
|
||||
import static org.elasticsearch.index.search.QueryParserHelper.resolveMappingFields;
|
||||
|
||||
/**
|
||||
* A {@link XQueryParser} that uses the {@link MapperService} in order to build smarter
|
||||
|
@ -264,6 +265,8 @@ public class QueryStringQueryParser extends XQueryParser {
|
|||
// Filters unsupported fields if a pattern is requested
|
||||
// Filters metadata fields if all fields are requested
|
||||
return resolveMappingField(context, field, 1.0f, !allFields, !multiFields, quoted ? quoteFieldSuffix : null);
|
||||
} else if (quoted && quoteFieldSuffix != null) {
|
||||
return resolveMappingFields(context, fieldsAndWeights, quoteFieldSuffix);
|
||||
} else {
|
||||
return fieldsAndWeights;
|
||||
}
|
||||
|
|
|
@ -1040,6 +1040,37 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
assertEquals(expectedQuery, query);
|
||||
}
|
||||
|
||||
public void testQuoteFieldSuffix() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext context = createShardContext();
|
||||
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
|
||||
new QueryStringQueryBuilder("bar")
|
||||
.quoteFieldSuffix("_2")
|
||||
.field(STRING_FIELD_NAME)
|
||||
.doToQuery(context)
|
||||
);
|
||||
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME_2, "bar")),
|
||||
new QueryStringQueryBuilder("\"bar\"")
|
||||
.quoteFieldSuffix("_2")
|
||||
.field(STRING_FIELD_NAME)
|
||||
.doToQuery(context)
|
||||
);
|
||||
|
||||
// Now check what happens if the quote field does not exist
|
||||
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
|
||||
new QueryStringQueryBuilder("bar")
|
||||
.quoteFieldSuffix(".quote")
|
||||
.field(STRING_FIELD_NAME)
|
||||
.doToQuery(context)
|
||||
);
|
||||
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
|
||||
new QueryStringQueryBuilder("\"bar\"")
|
||||
.quoteFieldSuffix(".quote")
|
||||
.field(STRING_FIELD_NAME)
|
||||
.doToQuery(context)
|
||||
);
|
||||
}
|
||||
|
||||
public void testToFuzzyQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
|
||||
|
|
Loading…
Reference in New Issue