query on _all field with term/prefix queries fail (by resulting on query execution exception) since the correct term query is not used for it
This commit is contained in:
parent
bf6cead984
commit
4ab298ce00
|
@ -162,15 +162,15 @@ public interface FieldMapper<T> {
|
|||
String indexedValue(T value);
|
||||
|
||||
/**
|
||||
* Should the field query {@link #fieldQuery(String)} be used when detecting this
|
||||
* Should the field query {@link #termQuery(String)} be used when detecting this
|
||||
* field in query string.
|
||||
*/
|
||||
boolean useFieldQueryWithQueryString();
|
||||
boolean useTermQueryWithQueryString();
|
||||
|
||||
/**
|
||||
* A field query for the specified value.
|
||||
*/
|
||||
Query fieldQuery(String value);
|
||||
Query termQuery(String value);
|
||||
|
||||
/**
|
||||
* A term query to use when parsing a query string. Can return <tt>null</tt>.
|
||||
|
|
|
@ -110,6 +110,10 @@ public class JsonAllFieldMapper extends JsonFieldMapper<Void> implements AllFiel
|
|||
return new AllTermQuery(term);
|
||||
}
|
||||
|
||||
@Override public Query termQuery(String value) {
|
||||
return new AllTermQuery(new Term(names.indexName(), value));
|
||||
}
|
||||
|
||||
@Override protected Field parseCreateField(JsonParseContext jsonContext) throws IOException {
|
||||
if (!enabled) {
|
||||
return null;
|
||||
|
@ -152,10 +156,6 @@ public class JsonAllFieldMapper extends JsonFieldMapper<Void> implements AllFiel
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override public String indexedValue(String value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public String indexedValue(Void value) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -319,11 +319,11 @@ public abstract class JsonFieldMapper<T> implements FieldMapper<T>, JsonMapper {
|
|||
return value.toString();
|
||||
}
|
||||
|
||||
@Override public boolean useFieldQueryWithQueryString() {
|
||||
@Override public boolean useTermQueryWithQueryString() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public Query fieldQuery(String value) {
|
||||
@Override public Query termQuery(String value) {
|
||||
return new TermQuery(new Term(names.indexName(), indexedValue(value)));
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ public abstract class JsonNumberFieldMapper<T extends Number> extends JsonFieldM
|
|||
/**
|
||||
* Use the field query created here when matching on numbers.
|
||||
*/
|
||||
@Override public boolean useFieldQueryWithQueryString() {
|
||||
@Override public boolean useTermQueryWithQueryString() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -93,7 +93,7 @@ public class TermJsonQueryParser extends AbstractIndexComponent implements JsonQ
|
|||
MapperService.SmartNameFieldMappers smartNameFieldMappers = parseContext.smartFieldMappers(fieldName);
|
||||
if (smartNameFieldMappers != null) {
|
||||
if (smartNameFieldMappers.hasMapper()) {
|
||||
query = smartNameFieldMappers.mapper().fieldQuery(value);
|
||||
query = smartNameFieldMappers.mapper().termQuery(value);
|
||||
}
|
||||
}
|
||||
if (query == null) {
|
||||
|
|
|
@ -82,8 +82,8 @@ public class MapperQueryParser extends QueryParser {
|
|||
currentMapper = fieldMappers.fieldMappers().mapper();
|
||||
if (currentMapper != null) {
|
||||
Query query;
|
||||
if (currentMapper.useFieldQueryWithQueryString()) {
|
||||
query = currentMapper.fieldQuery(queryText);
|
||||
if (currentMapper.useTermQueryWithQueryString()) {
|
||||
query = currentMapper.termQuery(queryText);
|
||||
} else {
|
||||
query = super.getFieldQuery(currentMapper.names().indexName(), queryText);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class HighlightSearchTests extends AbstractNodesTests {
|
|||
|
||||
@Test public void testSimpleHighlighting() throws Exception {
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(termQuery("multi", "test"))
|
||||
.query(termQuery("_all", "test"))
|
||||
.from(0).size(60).explain(true)
|
||||
.highlight(highlight().field("_all").order("score").preTags("<xxx>").postTags("</xxx>"));
|
||||
|
||||
|
@ -123,6 +123,26 @@ public class HighlightSearchTests extends AbstractNodesTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test public void testPrefixHighlightingOnAllField() throws Exception {
|
||||
SearchSourceBuilder source = searchSource()
|
||||
.query(prefixQuery("_all", "te"))
|
||||
.from(0).size(60).explain(true)
|
||||
.highlight(highlight().field("_all").order("score").preTags("<xxx>").postTags("</xxx>"));
|
||||
|
||||
SearchResponse searchResponse = client.search(searchRequest("test").source(source).searchType(QUERY_THEN_FETCH).scroll(timeValueMinutes(10))).actionGet();
|
||||
assertThat("Failures " + Arrays.toString(searchResponse.shardFailures()), searchResponse.shardFailures().length, equalTo(0));
|
||||
assertThat(searchResponse.hits().totalHits(), equalTo(100l));
|
||||
assertThat(searchResponse.hits().hits().length, equalTo(60));
|
||||
for (int i = 0; i < 60; i++) {
|
||||
SearchHit hit = searchResponse.hits().hits()[i];
|
||||
// System.out.println(hit.target() + ": " + hit.explanation());
|
||||
// assertThat("id[" + hit.id() + "]", hit.id(), equalTo(Integer.toString(100 - i - 1)));
|
||||
// System.out.println(hit.shard() + ": " + hit.highlightFields());
|
||||
assertThat(hit.highlightFields().size(), equalTo(1));
|
||||
assertThat(hit.highlightFields().get("_all").fragments().length, greaterThan(0));
|
||||
}
|
||||
}
|
||||
|
||||
private void index(Client client, String id, String nameValue, int age) throws IOException {
|
||||
client.index(Requests.indexRequest("test").type("type1").id(id).source(source(id, nameValue, age))).actionGet();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue