make fielddata fields a plugin
This commit is contained in:
parent
bcebb61f25
commit
5f0f66908e
|
@ -395,16 +395,6 @@ public class PercolateContext extends SearchContext {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFieldDataFields() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldDataFieldsContext fieldDataFields() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScriptFields() {
|
||||
throw new UnsupportedOperationException();
|
||||
|
|
|
@ -19,13 +19,14 @@
|
|||
package org.elasticsearch.search.fetch.fielddata;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.elasticsearch.search.fetch.FetchSubPhaseContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* All the required context to pull a field from the field data cache.
|
||||
*/
|
||||
public class FieldDataFieldsContext {
|
||||
public class FieldDataFieldsContext implements FetchSubPhaseContext{
|
||||
|
||||
public static class FieldDataField {
|
||||
private final String name;
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.elasticsearch.index.mapper.MappedFieldType;
|
|||
import org.elasticsearch.search.SearchHitField;
|
||||
import org.elasticsearch.search.SearchParseElement;
|
||||
import org.elasticsearch.search.fetch.FetchSubPhase;
|
||||
import org.elasticsearch.search.fetch.FetchSubPhaseContext;
|
||||
import org.elasticsearch.search.internal.InternalSearchHit;
|
||||
import org.elasticsearch.search.internal.InternalSearchHitField;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
@ -43,6 +44,20 @@ import java.util.Map;
|
|||
*/
|
||||
public class FieldDataFieldsFetchSubPhase implements FetchSubPhase {
|
||||
|
||||
public static final String[] NAMES = {"fielddata_fields", "fielddataFields"};
|
||||
public static final ContextFactory CONTEXT_FACTORY = new ContextFactory() {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAMES[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchSubPhaseContext newContextInstance() {
|
||||
return new FieldDataFieldsContext();
|
||||
}
|
||||
};
|
||||
|
||||
@Inject
|
||||
public FieldDataFieldsFetchSubPhase() {
|
||||
}
|
||||
|
@ -66,12 +81,12 @@ public class FieldDataFieldsFetchSubPhase implements FetchSubPhase {
|
|||
|
||||
@Override
|
||||
public boolean hitExecutionNeeded(SearchContext context) {
|
||||
return context.hasFieldDataFields();
|
||||
return context.hasFetchSubPhaseContext(CONTEXT_FACTORY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hitExecute(SearchContext context, HitContext hitContext) {
|
||||
for (FieldDataFieldsContext.FieldDataField field : context.fieldDataFields().fields()) {
|
||||
for (FieldDataFieldsContext.FieldDataField field : ((FieldDataFieldsContext)context.getFetchSubPhaseContext(CONTEXT_FACTORY)).fields()) {
|
||||
if (hitContext.hit().fieldsOrNull() == null) {
|
||||
hitContext.hit().fields(new HashMap<String, SearchHitField>(2));
|
||||
}
|
||||
|
|
|
@ -36,15 +36,16 @@ import org.elasticsearch.search.internal.SearchContext;
|
|||
public class FieldDataFieldsParseElement implements SearchParseElement {
|
||||
@Override
|
||||
public void parse(XContentParser parser, SearchContext context) throws Exception {
|
||||
FieldDataFieldsContext fieldDataFieldsContext = (FieldDataFieldsContext)context.getFetchSubPhaseContext(FieldDataFieldsFetchSubPhase.CONTEXT_FACTORY);
|
||||
XContentParser.Token token = parser.currentToken();
|
||||
if (token == XContentParser.Token.START_ARRAY) {
|
||||
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
|
||||
String fieldName = parser.text();
|
||||
context.fieldDataFields().add(new FieldDataFieldsContext.FieldDataField(fieldName));
|
||||
fieldDataFieldsContext.add(new FieldDataFieldsContext.FieldDataField(fieldName));
|
||||
}
|
||||
} else if (token == XContentParser.Token.VALUE_STRING) {
|
||||
String fieldName = parser.text();
|
||||
context.fieldDataFields().add(new FieldDataFieldsContext.FieldDataField(fieldName));
|
||||
fieldDataFieldsContext.add(new FieldDataFieldsContext.FieldDataField(fieldName));
|
||||
} else {
|
||||
throw new IllegalStateException("Expected either a VALUE_STRING or an START_ARRAY but got " + token);
|
||||
}
|
||||
|
|
|
@ -351,19 +351,6 @@ public class DefaultSearchContext extends SearchContext {
|
|||
this.rescore.add(rescore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFieldDataFields() {
|
||||
return fieldDataFields != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldDataFieldsContext fieldDataFields() {
|
||||
if (fieldDataFields == null) {
|
||||
fieldDataFields = new FieldDataFieldsContext();
|
||||
}
|
||||
return this.fieldDataFields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScriptFields() {
|
||||
return scriptFields != null;
|
||||
|
|
|
@ -211,16 +211,6 @@ public abstract class FilteredSearchContext extends SearchContext {
|
|||
in.addRescore(rescore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFieldDataFields() {
|
||||
return in.hasFieldDataFields();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldDataFieldsContext fieldDataFields() {
|
||||
return in.fieldDataFields();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScriptFields() {
|
||||
return in.hasScriptFields();
|
||||
|
|
|
@ -186,10 +186,6 @@ public abstract class SearchContext implements Releasable, HasContextAndHeaders
|
|||
|
||||
public abstract void addRescore(RescoreSearchContext rescore);
|
||||
|
||||
public abstract boolean hasFieldDataFields();
|
||||
|
||||
public abstract FieldDataFieldsContext fieldDataFields();
|
||||
|
||||
public abstract boolean hasScriptFields();
|
||||
|
||||
public abstract ScriptFieldsContext scriptFields();
|
||||
|
|
|
@ -132,19 +132,6 @@ public class SubSearchContext extends FilteredSearchContext {
|
|||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFieldDataFields() {
|
||||
return fieldDataFields != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldDataFieldsContext fieldDataFields() {
|
||||
if (fieldDataFields == null) {
|
||||
fieldDataFields = new FieldDataFieldsContext();
|
||||
}
|
||||
return this.fieldDataFields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScriptFields() {
|
||||
return scriptFields != null;
|
||||
|
|
|
@ -245,16 +245,6 @@ public class TestSearchContext extends SearchContext {
|
|||
public void addRescore(RescoreSearchContext rescore) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFieldDataFields() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FieldDataFieldsContext fieldDataFields() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasScriptFields() {
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue