Fix Source filtering in new field collapsing feature

Update ValueType of FetchSourceContext to OBJECT_ARRAY_BOOLEAN_OR_STRING to be in line with other source_filtering implementations
This commit is contained in:
Byron Voorbach 2017-05-12 09:38:16 +02:00 committed by Jim Ferenczi
parent 220bd2de6e
commit 70e14d5e3f
3 changed files with 9 additions and 4 deletions

View File

@ -409,6 +409,7 @@ public final class ObjectParser<Value, Context> extends AbstractObjectParser<Val
OBJECT_ARRAY(START_OBJECT, START_ARRAY),
OBJECT_OR_BOOLEAN(START_OBJECT, VALUE_BOOLEAN),
OBJECT_OR_STRING(START_OBJECT, VALUE_STRING),
OBJECT_ARRAY_BOOLEAN_OR_STRING(START_OBJECT, START_ARRAY, VALUE_BOOLEAN, VALUE_STRING),
OBJECT_ARRAY_OR_STRING(START_OBJECT, START_ARRAY, VALUE_STRING),
VALUE(VALUE_BOOLEAN, VALUE_NULL, VALUE_EMBEDDED_OBJECT, VALUE_NUMBER, VALUE_STRING);

View File

@ -101,7 +101,7 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
} catch (IOException e) {
throw new ParsingException(p.getTokenLocation(), "Could not parse inner _source definition", e);
}
}, SearchSourceBuilder._SOURCE_FIELD, ObjectParser.ValueType.OBJECT_OR_BOOLEAN);
}, SearchSourceBuilder._SOURCE_FIELD, ObjectParser.ValueType.OBJECT_ARRAY_BOOLEAN_OR_STRING);
PARSER.declareObject(InnerHitBuilder::setHighlightBuilder, (p, c) -> HighlightBuilder.fromXContent(c),
SearchSourceBuilder.HIGHLIGHT_FIELD);
PARSER.declareObject(InnerHitBuilder::setChildInnerHits, (p, c) -> {

View File

@ -19,6 +19,7 @@
package org.elasticsearch.index.query;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.Settings;
@ -311,13 +312,16 @@ public class InnerHitBuilderTests extends ESTestCase {
}
innerHits.setScriptFields(new HashSet<>(scriptFields.values()));
FetchSourceContext randomFetchSourceContext;
if (randomBoolean()) {
randomFetchSourceContext = new FetchSourceContext(randomBoolean());
} else {
int randomInt = randomIntBetween(0, 2);
if (randomInt == 0) {
randomFetchSourceContext = new FetchSourceContext(true, Strings.EMPTY_ARRAY, Strings.EMPTY_ARRAY);
} else if (randomInt == 1) {
randomFetchSourceContext = new FetchSourceContext(true,
generateRandomStringArray(12, 16, false),
generateRandomStringArray(12, 16, false)
);
} else {
randomFetchSourceContext = new FetchSourceContext(randomBoolean());
}
innerHits.setFetchSourceContext(randomFetchSourceContext);
if (randomBoolean()) {