review comment fixes
This commit is contained in:
parent
117d8d2606
commit
7fbd565c5c
|
@ -25,7 +25,6 @@ import org.elasticsearch.action.ActionResponse;
|
|||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -69,7 +68,10 @@ public class GetWarmersResponse extends ActionResponse {
|
|||
for (int j = 0; j < valueSize; j++) {
|
||||
String name = in.readString();
|
||||
String[] types = in.readStringArray();
|
||||
IndexWarmersMetaData.SearchSource source = new IndexWarmersMetaData.SearchSource(in);
|
||||
IndexWarmersMetaData.SearchSource source = null;
|
||||
if (in.readBoolean()) {
|
||||
source = new IndexWarmersMetaData.SearchSource(in);
|
||||
}
|
||||
Boolean queryCache = null;
|
||||
queryCache = in.readOptionalBoolean();
|
||||
warmerEntryBuilder.add(new IndexWarmersMetaData.Entry(
|
||||
|
@ -94,7 +96,11 @@ public class GetWarmersResponse extends ActionResponse {
|
|||
for (IndexWarmersMetaData.Entry warmerEntry : indexEntry.value) {
|
||||
out.writeString(warmerEntry.name());
|
||||
out.writeStringArray(warmerEntry.types());
|
||||
warmerEntry.source().writeTo(out);
|
||||
boolean hasWarmerSource = warmerEntry != null;
|
||||
out.writeBoolean(hasWarmerSource);
|
||||
if (hasWarmerSource) {
|
||||
warmerEntry.source().writeTo(out);
|
||||
}
|
||||
out.writeOptionalBoolean(warmerEntry.requestCache());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,26 +19,18 @@
|
|||
|
||||
package org.elasticsearch.action.count;
|
||||
|
||||
import org.elasticsearch.ElasticsearchGenerationException;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.support.QuerySourceBuilder;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastRequest;
|
||||
import org.elasticsearch.client.Requests;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_AFTER;
|
||||
|
||||
|
@ -66,7 +58,7 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
|
||||
private int terminateAfter = DEFAULT_TERMINATE_AFTER;
|
||||
|
||||
private SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
private QueryBuilder<?> queryBuilder = null;
|
||||
|
||||
/**
|
||||
* Constructs a new count request against the provided indices. No indices provided means it will
|
||||
|
@ -96,13 +88,8 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
/**
|
||||
* The query to execute
|
||||
*/
|
||||
public CountRequest query(QueryBuilder queryBuilder) {
|
||||
this.searchSourceBuilder = new SearchSourceBuilder().query(queryBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CountRequest searchSource(SearchSourceBuilder searchSourceBuilder) {
|
||||
this.searchSourceBuilder = searchSourceBuilder;
|
||||
public CountRequest query(QueryBuilder<?> queryBuilder) {
|
||||
this.queryBuilder = queryBuilder;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -184,7 +171,7 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
public String toString() {
|
||||
String sSource = "_na_";
|
||||
try {
|
||||
sSource = XContentHelper.toString(searchSourceBuilder);
|
||||
sSource = XContentHelper.toString(queryBuilder);
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
|
@ -192,6 +179,8 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
}
|
||||
|
||||
public SearchRequest toSearchRequest() {
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
searchSourceBuilder.query(queryBuilder);
|
||||
searchSourceBuilder.size(0);
|
||||
if (minScore() != DEFAULT_MIN_SCORE) {
|
||||
searchSourceBuilder.minScore(minScore());
|
||||
|
@ -207,8 +196,4 @@ public class CountRequest extends BroadcastRequest<CountRequest> {
|
|||
searchRequest.preference(preference());
|
||||
return searchRequest;
|
||||
}
|
||||
|
||||
SearchSourceBuilder sourceBuilder() {
|
||||
return searchSourceBuilder;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.action.count;
|
||||
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.search.SearchAction;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
@ -27,11 +26,7 @@ import org.elasticsearch.action.support.DelegatingActionListener;
|
|||
import org.elasticsearch.action.support.QuerySourceBuilder;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
|
||||
/**
|
||||
* A count action request builder.
|
||||
|
@ -86,14 +81,6 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder<CountR
|
|||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The source to execute.
|
||||
*/
|
||||
public CountRequestBuilder setSource(SearchSourceBuilder source) {
|
||||
request().searchSource(source);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The query source to execute.
|
||||
*/
|
||||
|
@ -120,8 +107,8 @@ public class CountRequestBuilder extends BroadcastOperationRequestBuilder<CountR
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (request.sourceBuilder() != null) {
|
||||
return request.sourceBuilder().toString();
|
||||
if (request != null) {
|
||||
return request.toString();
|
||||
}
|
||||
return new QuerySourceBuilder().toString();
|
||||
}
|
||||
|
|
|
@ -102,7 +102,10 @@ public class DfsOnlyRequest extends BroadcastRequest<DfsOnlyRequest> {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
String sSource = searchRequest.source().toString();
|
||||
String sSource = "_na_";
|
||||
if (searchRequest.source() != null) {
|
||||
sSource = searchRequest.source().toString();
|
||||
}
|
||||
return "[" + Arrays.toString(indices) + "]" + Arrays.toString(types()) + ", source[" + sSource + "]";
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.cluster.metadata;
|
|||
|
||||
import com.carrotsearch.hppc.cursors.ObjectCursor;
|
||||
import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.Diff;
|
||||
|
@ -41,11 +40,7 @@ import org.elasticsearch.common.io.stream.StreamInput;
|
|||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.loader.SettingsLoader;
|
||||
import org.elasticsearch.common.xcontent.FromXContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.*;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.warmer.IndexWarmersMetaData;
|
||||
|
@ -61,14 +56,12 @@ import java.util.Map;
|
|||
|
||||
import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.AND;
|
||||
import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.OR;
|
||||
import static org.elasticsearch.common.settings.Settings.readSettingsFromStream;
|
||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||
import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
|
||||
import static org.elasticsearch.common.settings.Settings.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuilder<IndexMetaData>, ToXContent {
|
||||
public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuilder<IndexMetaData>, ToXContent {
|
||||
|
||||
public static final IndexMetaData PROTO = IndexMetaData.builder("")
|
||||
.settings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT))
|
||||
|
@ -531,8 +524,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|||
}
|
||||
|
||||
@Override
|
||||
public IndexMetaData fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher)
|
||||
throws IOException {
|
||||
public IndexMetaData fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException {
|
||||
return Builder.fromXContent(parser);
|
||||
}
|
||||
|
||||
|
@ -713,7 +705,7 @@ public class IndexMetaData implements Diffable<IndexMetaData>, FromXContentBuild
|
|||
public int numberOfReplicas() {
|
||||
return settings.getAsInt(SETTING_NUMBER_OF_REPLICAS, -1);
|
||||
}
|
||||
|
||||
|
||||
public Builder creationDate(long creationDate) {
|
||||
settings = settingsBuilder().put(settings).put(SETTING_CREATION_DATE, creationDate).build();
|
||||
return this;
|
||||
|
|
|
@ -26,9 +26,6 @@ import org.elasticsearch.common.Strings;
|
|||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
|
@ -75,10 +72,7 @@ public class RestPutWarmerAction extends BaseRestHandler {
|
|||
PutWarmerRequest putWarmerRequest = new PutWarmerRequest(request.param("name"));
|
||||
|
||||
BytesReference sourceBytes = RestActions.getRestContent(request);
|
||||
XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes);
|
||||
QueryParseContext queryParseContext = new QueryParseContext(queryRegistry);
|
||||
queryParseContext.reset(parser);
|
||||
SearchSourceBuilder source = SearchSourceBuilder.PROTOTYPE.fromXContent(parser, queryParseContext);
|
||||
SearchSourceBuilder source = RestActions.getRestSearchSource(sourceBytes, queryRegistry);
|
||||
SearchRequest searchRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")))
|
||||
.types(Strings.splitStringByCommaToArray(request.param("type")))
|
||||
.requestCache(request.paramAsBoolean("request_cache", null)).source(source);
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.action.count.CountRequest;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.support.QuerySourceBuilder;
|
||||
import org.elasticsearch.bootstrap.Elasticsearch;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.Table;
|
||||
|
@ -38,11 +37,9 @@ import org.elasticsearch.rest.RestChannel;
|
|||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.action.search.RestSearchAction;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestResponseListener;
|
||||
import org.elasticsearch.rest.action.support.RestTable;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
|
@ -78,8 +75,8 @@ public class RestCountAction extends AbstractCatAction {
|
|||
try (XContentParser requestParser = XContentFactory.xContent(source).createParser(source)) {
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
|
||||
context.reset(requestParser);
|
||||
final SearchSourceBuilder builder = SearchSourceBuilder.PROTOTYPE.fromXContent(requestParser, context);
|
||||
countRequest.searchSource(builder);
|
||||
final QueryBuilder<?> builder = context.parseInnerQueryBuilder();
|
||||
countRequest.query(builder);
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException("failed to parse source", e);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.action.count.CountRequest;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.action.support.QuerySourceBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
|
@ -43,7 +42,6 @@ import org.elasticsearch.rest.RestRequest;
|
|||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -81,8 +79,8 @@ public class RestCountAction extends BaseRestHandler {
|
|||
try (XContentParser requestParser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
|
||||
context.reset(requestParser);
|
||||
final SearchSourceBuilder builder = SearchSourceBuilder.PROTOTYPE.fromXContent(requestParser, context);
|
||||
countRequest.searchSource(builder);
|
||||
final QueryBuilder<?> builder = context.parseInnerQueryBuilder();
|
||||
countRequest.query(builder);
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException("failed to parse source", e);
|
||||
}
|
||||
|
|
|
@ -115,10 +115,7 @@ public class RestSearchAction extends BaseRestHandler {
|
|||
}
|
||||
builder = null;
|
||||
} else {
|
||||
try (XContentParser requestParser = XContentFactory.xContent(restContent).createParser(restContent)) {
|
||||
context.reset(requestParser);
|
||||
builder = SearchSourceBuilder.PROTOTYPE.fromXContent(requestParser, context);
|
||||
}
|
||||
builder = RestActions.getRestSearchSource(restContent, indicesQueriesRegistry);
|
||||
}
|
||||
} else {
|
||||
builder = null;
|
||||
|
|
|
@ -29,12 +29,16 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilderString;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.Operator;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.index.query.QueryStringQueryBuilder;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -107,6 +111,15 @@ public class RestActions {
|
|||
return queryBuilder;
|
||||
}
|
||||
|
||||
public static SearchSourceBuilder getRestSearchSource(BytesReference sourceBytes, IndicesQueriesRegistry queryRegistry)
|
||||
throws IOException {
|
||||
XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes);
|
||||
QueryParseContext queryParseContext = new QueryParseContext(queryRegistry);
|
||||
queryParseContext.reset(parser);
|
||||
SearchSourceBuilder source = SearchSourceBuilder.PROTOTYPE.fromXContent(parser, queryParseContext);
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rest content from either payload or source parameter
|
||||
* @param request Rest request
|
||||
|
|
|
@ -22,23 +22,14 @@ package org.elasticsearch.action.count;
|
|||
import org.elasticsearch.action.support.QuerySourceBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||
import org.elasticsearch.index.query.MatchQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
|
@ -81,11 +72,4 @@ public class CountRequestBuilderTests extends ESTestCase {
|
|||
countRequestBuilder.setQuery(new MatchAllQueryBuilder());
|
||||
assertThat(countRequestBuilder.toString(), containsString("match_all"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringSourceToString() {
|
||||
CountRequestBuilder countRequestBuilder = client.prepareCount();
|
||||
countRequestBuilder.setSource(new SearchSourceBuilder().query(new MatchAllQueryBuilder()));
|
||||
assertThat(countRequestBuilder.toString(), containsString("match_all"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue