Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.elasticsearch.action.support.replication.ReplicationRequest;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
Expand Down Expand Up @@ -361,7 +360,7 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
} else if ("fields".equals(currentFieldName)) {
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains a simple value for parameter [fields] while a list is expected");
} else if ("_source".equals(currentFieldName)) {
fetchSourceContext = FetchSourceContext.parse(parser, ParseFieldMatcher.EMPTY);
fetchSourceContext = FetchSourceContext.parse(parser);
} else {
throw new IllegalArgumentException("Action/metadata line [" + line + "] contains an unknown parameter [" + currentFieldName + "]");
}
Expand All @@ -374,7 +373,7 @@ public BulkRequest add(BytesReference data, @Nullable String defaultIndex, @Null
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
}
} else if (token == XContentParser.Token.START_OBJECT && "_source".equals(currentFieldName)) {
fetchSourceContext = FetchSourceContext.parse(parser, ParseFieldMatcher.STRICT);
fetchSourceContext = FetchSourceContext.parse(parser);
} else if (token != XContentParser.Token.VALUE_NULL) {
throw new IllegalArgumentException("Malformed action/metadata line [" + line + "], expected a simple value for field [" + currentFieldName + "] but found [" + token + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
parent = parser.text();
} else if ("fields".equals(currentFieldName)) {
throw new ParsingException(parser.getTokenLocation(),
"Deprecated field [fields] used, expected [stored_fields] instead");
"Unsupported field [fields] used, expected [stored_fields] instead");
} else if ("stored_fields".equals(currentFieldName)) {
storedFields = new ArrayList<>();
storedFields.add(parser.text());
Expand All @@ -411,7 +411,7 @@ public static void parseDocuments(XContentParser parser, List<Item> items, @Null
} else if (token == XContentParser.Token.START_ARRAY) {
if ("fields".equals(currentFieldName)) {
throw new ParsingException(parser.getTokenLocation(),
"Deprecated field [fields] used, expected [stored_fields] instead");
"Unsupported field [fields] used, expected [stored_fields] instead");
} else if ("stored_fields".equals(currentFieldName)) {
storedFields = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.elasticsearch.action.ValidateActions.addValidationError;

Expand Down Expand Up @@ -745,22 +745,17 @@ public UpdateRequest fromXContent(BytesReference source) throws Exception {
} else if ("detect_noop".equals(currentFieldName)) {
detectNoop(parser.booleanValue());
} else if ("fields".equals(currentFieldName)) {
List<Object> fields = null;
if (token == XContentParser.Token.START_ARRAY) {
List<String> strings = parser.list().stream()
.filter((o) -> {
if (o instanceof String == false) {
throw new IllegalArgumentException("");
}
return true;
})
.map(o -> o.toString())
.collect(Collectors.toList());
fields(strings.toArray(new String[strings.size()]));
fields = (List) parser.list();
} else if (token.isValue()) {
fields(parser.text());
fields = Collections.singletonList(parser.text());
}
if (fields != null) {
fields(fields.toArray(new String[fields.size()]));
}
} else if ("_source".equals(currentFieldName)) {
fetchSourceContext = FetchSourceContext.parse(parser, ParseFieldMatcher.EMPTY);
fetchSourceContext = FetchSourceContext.parse(parser);
}
}
if (script != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.elasticsearch.action.support.single.instance.InstanceShardOperationRequestBuilder;
import org.elasticsearch.client.ElasticsearchClient;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.unit.TimeValue;
Expand Down Expand Up @@ -330,26 +329,6 @@ public UpdateRequestBuilder setUpsert(Object... source) {
return this;
}

public UpdateRequestBuilder fromXContent(XContentBuilder source) throws Exception {
request.fromXContent(source);
return this;
}

public UpdateRequestBuilder fromXContent(byte[] source) throws Exception {
request.fromXContent(source);
return this;
}

public UpdateRequestBuilder fromXContent(byte[] source, int offset, int length) throws Exception {
request.fromXContent(source, offset, length);
return this;
}

public UpdateRequestBuilder fromXContent(BytesReference source) throws Exception {
request.fromXContent(source);
return this;
}

/**
* Sets whether the specified doc parameter should be used as upsert document.
*/
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/elasticsearch/index/get/GetResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.search.lookup.SourceLookup;

import java.io.IOException;
Expand Down Expand Up @@ -204,7 +205,6 @@ static final class Fields {
static final String _VERSION = "_version";
static final String FOUND = "found";
static final String FIELDS = "fields";
static final String _SOURCE = "_source";
}

public XContentBuilder toXContentEmbedded(XContentBuilder builder, Params params) throws IOException {
Expand All @@ -230,7 +230,7 @@ public XContentBuilder toXContentEmbedded(XContentBuilder builder, Params params
builder.field(Fields.FOUND, exists);

if (source != null) {
XContentHelper.writeRawField(Fields._SOURCE, source, builder, params);
XContentHelper.writeRawField(SourceFieldMapper.NAME, source, builder, params);
}

if (!otherFields.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public final class InnerHitBuilder extends ToXContentToBytes implements Writeabl
ObjectParser.ValueType.OBJECT_ARRAY);
PARSER.declareField((p, i, c) -> {
try {
i.setFetchSourceContext(FetchSourceContext.parse(c.parser(), c.getParseFieldMatcher()));
i.setFetchSourceContext(FetchSourceContext.parse(c.parser()));
} catch (IOException e) {
throw new ParsingException(p.getTokenLocation(), "Could not parse inner _source definition", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void handleRequest(final RestRequest request, final RestChannel channel,
getRequest.realtime(request.paramAsBoolean("realtime", getRequest.realtime()));
if (request.param("fields") != null) {
throw new IllegalArgumentException("The parameter [fields] is no longer supported, " +
"please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored");
"please use [stored_fields] to retrieve stored fields or or [_source] to load the field from _source");
}
String sField = request.param("stored_fields");
if (sField != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ public static TopHitsAggregationBuilder parse(String aggregationName, QueryParse
} else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.TRACK_SCORES_FIELD)) {
factory.trackScores(parser.booleanValue());
} else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) {
factory.fetchSource(FetchSourceContext.parse(context.parser(), context.getParseFieldMatcher()));
factory.fetchSource(FetchSourceContext.parse(context.parser()));
} else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.STORED_FIELDS_FIELD)) {
factory.storedFieldsContext =
StoredFieldsContext.fromXContent(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName(), context);
Expand All @@ -608,7 +608,7 @@ public static TopHitsAggregationBuilder parse(String aggregationName, QueryParse
}
} else if (token == XContentParser.Token.START_OBJECT) {
if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) {
factory.fetchSource(FetchSourceContext.parse(context.parser(), context.getParseFieldMatcher()));
factory.fetchSource(FetchSourceContext.parse(context.parser()));
} else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELDS_FIELD)) {
List<ScriptField> scriptFields = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
Expand Down Expand Up @@ -680,7 +680,7 @@ public static TopHitsAggregationBuilder parse(String aggregationName, QueryParse
List<SortBuilder<?>> sorts = SortBuilder.fromXContent(context);
factory.sorts(sorts);
} else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) {
factory.fetchSource(FetchSourceContext.parse(context.parser(), context.getParseFieldMatcher()));
factory.fetchSource(FetchSourceContext.parse(context.parser()));
} else {
throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].",
parser.getTokenLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ public void parseXContent(QueryParseContext context, AggregatorParsers aggParser
} else if (context.getParseFieldMatcher().match(currentFieldName, TRACK_SCORES_FIELD)) {
trackScores = parser.booleanValue();
} else if (context.getParseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) {
fetchSourceContext = FetchSourceContext.parse(context.parser(), context.getParseFieldMatcher());
fetchSourceContext = FetchSourceContext.parse(context.parser());
} else if (context.getParseFieldMatcher().match(currentFieldName, STORED_FIELDS_FIELD)) {
storedFieldsContext =
StoredFieldsContext.fromXContent(SearchSourceBuilder.STORED_FIELDS_FIELD.getPreferredName(), context);
Expand All @@ -983,7 +983,7 @@ public void parseXContent(QueryParseContext context, AggregatorParsers aggParser
} else if (context.getParseFieldMatcher().match(currentFieldName, POST_FILTER_FIELD)) {
postQueryBuilder = context.parseInnerQueryBuilder().orElse(null);
} else if (context.getParseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) {
fetchSourceContext = FetchSourceContext.parse(context.parser(), context.getParseFieldMatcher());
fetchSourceContext = FetchSourceContext.parse(context.parser());
} else if (context.getParseFieldMatcher().match(currentFieldName, SCRIPT_FIELDS_FIELD)) {
scriptFields = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
Expand Down Expand Up @@ -1068,7 +1068,7 @@ public void parseXContent(QueryParseContext context, AggregatorParsers aggParser
}
}
} else if (context.getParseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) {
fetchSourceContext = FetchSourceContext.parse(context.parser(), context.getParseFieldMatcher());
fetchSourceContext = FetchSourceContext.parse(context.parser());
} else if (context.getParseFieldMatcher().match(currentFieldName, SEARCH_AFTER)) {
searchAfterBuilder = SearchAfterBuilder.fromXContent(parser, context.getParseFieldMatcher());
} else if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ public class FetchSourceContext implements Writeable, ToXContent {
private String[] includes;
private String[] excludes;

public static FetchSourceContext parse(XContentParser parser,
ParseFieldMatcher parseFieldMatcher) throws IOException {
public static FetchSourceContext parse(XContentParser parser) throws IOException {
FetchSourceContext fetchSourceContext = new FetchSourceContext();
fetchSourceContext.fromXContent(parser, parseFieldMatcher);
fetchSourceContext.fromXContent(parser, ParseFieldMatcher.STRICT);
return fetchSourceContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ public void testBulkUpdateLargerVolume() throws Exception {
assertThat(response.getItems()[i].getType(), equalTo("type1"));
assertThat(response.getItems()[i].getOpType(), equalTo("update"));
for (int j = 0; j < 5; j++) {
GetResponse getResponse = client().prepareGet("test", "type1", Integer.toString(i)).execute()
.actionGet();
GetResponse getResponse = client().prepareGet("test", "type1", Integer.toString(i)).get();
assertThat(getResponse.isExists(), equalTo(false));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ public void testUpdateRequest() throws Exception {
// script with params
request = new UpdateRequest("test", "type", "1");
request.fromXContent(XContentFactory.jsonBuilder().startObject()
.startObject("script").field("inline", "script1")
.startObject("params").field("param1", "value1")
.endObject().endObject().endObject());
.startObject("script")
.field("inline", "script1")
.startObject("params")
.field("param1", "value1")
.endObject()
.endObject().endObject());
script = request.script();
assertThat(script, notNullValue());
assertThat(script.getScript(), equalTo("script1"));
Expand All @@ -103,10 +106,13 @@ public void testUpdateRequest() throws Exception {

// script with params and upsert
request = new UpdateRequest("test", "type", "1");
request.fromXContent(XContentFactory.jsonBuilder().startObject().startObject("script")
.startObject("params")
.field("param1", "value1").endObject()
.field("inline", "script1").endObject()
request.fromXContent(XContentFactory.jsonBuilder().startObject()
.startObject("script")
.startObject("params")
.field("param1", "value1")
.endObject()
.field("inline", "script1")
.endObject()
.startObject("upsert")
.field("field1", "value1")
.startObject("compound")
Expand Down Expand Up @@ -258,8 +264,8 @@ public void testFetchSourceParsing() throws Exception {
request.fromXContent(
XContentFactory.jsonBuilder().startObject()
.startObject("_source")
.field("include", "path.inner.*")
.field("exclude", "another.inner.*")
.field("includes", "path.inner.*")
.field("excludes", "another.inner.*")
.endObject()
.endObject()
);
Expand Down
21 changes: 9 additions & 12 deletions core/src/test/java/org/elasticsearch/get/GetActionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -586,21 +586,18 @@ public void testGetFieldsNonLeafField() throws Exception {
.setSource(jsonBuilder().startObject().startObject("field1").field("field2", "value1").endObject().endObject())
.get();

try {
client().prepareGet(indexOrAlias(), "my-type1", "1").setStoredFields("field1").get();
fail();
} catch (IllegalArgumentException e) {
//all well
}

IllegalArgumentException exc =
expectThrows(IllegalArgumentException.class,
() -> client().prepareGet(indexOrAlias(), "my-type1", "1").setStoredFields("field1").get());
assertThat(exc.getMessage(), equalTo("field [field1] isn't a leaf field"));

flush();

try {
client().prepareGet(indexOrAlias(), "my-type1", "1").setStoredFields("field1").get();
fail();
} catch (IllegalArgumentException e) {
//all well
}
exc =
expectThrows(IllegalArgumentException.class,
() -> client().prepareGet(indexOrAlias(), "my-type1", "1").setStoredFields("field1").get());
assertThat(exc.getMessage(), equalTo("field [field1] isn't a leaf field"));
}

public void testGetFieldsComplexField() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ public void testReplicaToPrimaryPromotion() throws Exception {
client().prepareIndex(IDX, "doc", "1").setSource("foo", "bar").get();
client().prepareIndex(IDX, "doc", "2").setSource("foo", "bar").get();


GetResponse gResp1 = client().prepareGet(IDX, "doc", "1").get();
GetResponse gResp2 = client().prepareGet(IDX, "doc", "2").get();
assertTrue(gResp1.isExists());
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/org/elasticsearch/update/UpdateIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ public void testUpdate() throws Exception {
updateResponse = client().prepareUpdate(indexOrAlias(), "type1", "1")
.setScript(new Script("field1", ScriptService.ScriptType.INLINE, "field_inc", null))
.setFetchSource("field1", "field2")
.execute().actionGet();
.get();
assertThat(updateResponse.getIndex(), equalTo("test"));
assertThat(updateResponse.getGetResult(), notNullValue());
assertThat(updateResponse.getGetResult().getIndex(), equalTo("test"));
Expand Down
2 changes: 1 addition & 1 deletion docs/groovy-api/search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def search = node.client.search {
source {
query {
query_string(
stored_fields: ["test"],
fields: ["test"],
query: "value1 value2")
}
}
Expand Down
Loading