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_ARRAY(START_OBJECT, START_ARRAY),
OBJECT_OR_BOOLEAN(START_OBJECT, VALUE_BOOLEAN), OBJECT_OR_BOOLEAN(START_OBJECT, VALUE_BOOLEAN),
OBJECT_OR_STRING(START_OBJECT, VALUE_STRING), 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), OBJECT_ARRAY_OR_STRING(START_OBJECT, START_ARRAY, VALUE_STRING),
VALUE(VALUE_BOOLEAN, VALUE_NULL, VALUE_EMBEDDED_OBJECT, VALUE_NUMBER, 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) { } catch (IOException e) {
throw new ParsingException(p.getTokenLocation(), "Could not parse inner _source definition", 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), PARSER.declareObject(InnerHitBuilder::setHighlightBuilder, (p, c) -> HighlightBuilder.fromXContent(c),
SearchSourceBuilder.HIGHLIGHT_FIELD); SearchSourceBuilder.HIGHLIGHT_FIELD);
PARSER.declareObject(InnerHitBuilder::setChildInnerHits, (p, c) -> { PARSER.declareObject(InnerHitBuilder::setChildInnerHits, (p, c) -> {

View File

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