Put method addField on TopHitsBuilder
This commit is contained in:
parent
f03196193f
commit
202a735d8f
|
@ -88,6 +88,14 @@ public class TopHitsBuilder extends AbstractAggregationBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a field to loaded and returned.
|
||||||
|
*/
|
||||||
|
public TopHitsBuilder addField(String field) {
|
||||||
|
sourceBuilder().field(field);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets no fields to be loaded, resulting in only id and type to be returned per field.
|
* Sets no fields to be loaded, resulting in only id and type to be returned per field.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.elasticsearch.search.SearchParseException;
|
||||||
import org.elasticsearch.search.aggregations.Aggregator;
|
import org.elasticsearch.search.aggregations.Aggregator;
|
||||||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||||
import org.elasticsearch.search.fetch.FetchPhase;
|
import org.elasticsearch.search.fetch.FetchPhase;
|
||||||
|
import org.elasticsearch.search.fetch.FieldsParseElement;
|
||||||
import org.elasticsearch.search.fetch.fielddata.FieldDataFieldsParseElement;
|
import org.elasticsearch.search.fetch.fielddata.FieldDataFieldsParseElement;
|
||||||
import org.elasticsearch.search.fetch.script.ScriptFieldsParseElement;
|
import org.elasticsearch.search.fetch.script.ScriptFieldsParseElement;
|
||||||
import org.elasticsearch.search.fetch.source.FetchSourceParseElement;
|
import org.elasticsearch.search.fetch.source.FetchSourceParseElement;
|
||||||
|
@ -46,15 +47,19 @@ public class TopHitsParser implements Aggregator.Parser {
|
||||||
private final HighlighterParseElement highlighterParseElement;
|
private final HighlighterParseElement highlighterParseElement;
|
||||||
private final FieldDataFieldsParseElement fieldDataFieldsParseElement;
|
private final FieldDataFieldsParseElement fieldDataFieldsParseElement;
|
||||||
private final ScriptFieldsParseElement scriptFieldsParseElement;
|
private final ScriptFieldsParseElement scriptFieldsParseElement;
|
||||||
|
private final FieldsParseElement fieldsParseElement;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TopHitsParser(FetchPhase fetchPhase, SortParseElement sortParseElement, FetchSourceParseElement sourceParseElement, HighlighterParseElement highlighterParseElement, FieldDataFieldsParseElement fieldDataFieldsParseElement, ScriptFieldsParseElement scriptFieldsParseElement) {
|
public TopHitsParser(FetchPhase fetchPhase, SortParseElement sortParseElement, FetchSourceParseElement sourceParseElement,
|
||||||
|
HighlighterParseElement highlighterParseElement, FieldDataFieldsParseElement fieldDataFieldsParseElement,
|
||||||
|
ScriptFieldsParseElement scriptFieldsParseElement, FieldsParseElement fieldsParseElement) {
|
||||||
this.fetchPhase = fetchPhase;
|
this.fetchPhase = fetchPhase;
|
||||||
this.sortParseElement = sortParseElement;
|
this.sortParseElement = sortParseElement;
|
||||||
this.sourceParseElement = sourceParseElement;
|
this.sourceParseElement = sourceParseElement;
|
||||||
this.highlighterParseElement = highlighterParseElement;
|
this.highlighterParseElement = highlighterParseElement;
|
||||||
this.fieldDataFieldsParseElement = fieldDataFieldsParseElement;
|
this.fieldDataFieldsParseElement = fieldDataFieldsParseElement;
|
||||||
this.scriptFieldsParseElement = scriptFieldsParseElement;
|
this.scriptFieldsParseElement = scriptFieldsParseElement;
|
||||||
|
this.fieldsParseElement = fieldsParseElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,6 +80,8 @@ public class TopHitsParser implements Aggregator.Parser {
|
||||||
sortParseElement.parse(parser, subSearchContext);
|
sortParseElement.parse(parser, subSearchContext);
|
||||||
} else if ("_source".equals(currentFieldName)) {
|
} else if ("_source".equals(currentFieldName)) {
|
||||||
sourceParseElement.parse(parser, subSearchContext);
|
sourceParseElement.parse(parser, subSearchContext);
|
||||||
|
} else if ("fields".equals(currentFieldName)) {
|
||||||
|
fieldsParseElement.parse(parser, subSearchContext);
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
switch (currentFieldName) {
|
switch (currentFieldName) {
|
||||||
case "from":
|
case "from":
|
||||||
|
|
|
@ -533,6 +533,7 @@ public class TopHitsIT extends ESIntegTestCase {
|
||||||
.highlighter(new HighlightBuilder().field("text"))
|
.highlighter(new HighlightBuilder().field("text"))
|
||||||
.setExplain(true)
|
.setExplain(true)
|
||||||
.addFieldDataField("field1")
|
.addFieldDataField("field1")
|
||||||
|
.addField("text")
|
||||||
.addScriptField("script", new Script("5", ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap()))
|
.addScriptField("script", new Script("5", ScriptService.ScriptType.INLINE, MockScriptEngine.NAME, Collections.emptyMap()))
|
||||||
.setFetchSource("text", null)
|
.setFetchSource("text", null)
|
||||||
.setVersion(true)
|
.setVersion(true)
|
||||||
|
@ -568,6 +569,9 @@ public class TopHitsIT extends ESIntegTestCase {
|
||||||
SearchHitField field = hit.field("field1");
|
SearchHitField field = hit.field("field1");
|
||||||
assertThat(field.getValue().toString(), equalTo("5"));
|
assertThat(field.getValue().toString(), equalTo("5"));
|
||||||
|
|
||||||
|
field = hit.field("text");
|
||||||
|
assertThat(field.getValue().toString(), equalTo("some text to entertain"));
|
||||||
|
|
||||||
field = hit.field("script");
|
field = hit.field("script");
|
||||||
assertThat(field.getValue().toString(), equalTo("5"));
|
assertThat(field.getValue().toString(), equalTo("5"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue