|
@@ -42,6 +42,7 @@ import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
|
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
|
|
+import org.elasticsearch.common.logging.DeprecationLogger;
|
|
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
|
|
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
|
|
|
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
@@ -51,10 +52,12 @@ import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
|
|
import org.elasticsearch.common.xcontent.XContentParser;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
+import org.elasticsearch.core.RestApiVersion;
|
|
|
import org.elasticsearch.index.fielddata.IndexFieldData;
|
|
|
import org.elasticsearch.index.fielddata.IndexFieldDataCache;
|
|
|
import org.elasticsearch.index.mapper.LuceneDocument;
|
|
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
|
|
+import org.elasticsearch.index.mapper.MapperService;
|
|
|
import org.elasticsearch.index.mapper.ParsedDocument;
|
|
|
import org.elasticsearch.index.mapper.SourceToParse;
|
|
|
import org.elasticsearch.index.query.AbstractQueryBuilder;
|
|
@@ -74,19 +77,30 @@ import java.util.Collection;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.function.BiConsumer;
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
|
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
|
|
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
|
|
|
+import static org.elasticsearch.core.RestApiVersion.equalTo;
|
|
|
import static org.elasticsearch.search.SearchService.ALLOW_EXPENSIVE_QUERIES;
|
|
|
|
|
|
public class PercolateQueryBuilder extends AbstractQueryBuilder<PercolateQueryBuilder> {
|
|
|
+ private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(ParseField.class);
|
|
|
+ static final String DOCUMENT_TYPE_DEPRECATION_MESSAGE = "[types removal] Types are deprecated in [percolate] queries. " +
|
|
|
+ "The [document_type] should no longer be specified.";
|
|
|
+ static final String TYPE_DEPRECATION_MESSAGE = "[types removal] Types are deprecated in [percolate] queries. " +
|
|
|
+ "The [type] of the indexed document should no longer be specified.";
|
|
|
+
|
|
|
+
|
|
|
public static final String NAME = "percolate";
|
|
|
|
|
|
static final ParseField DOCUMENT_FIELD = new ParseField("document");
|
|
|
static final ParseField DOCUMENTS_FIELD = new ParseField("documents");
|
|
|
private static final ParseField NAME_FIELD = new ParseField("name");
|
|
|
private static final ParseField QUERY_FIELD = new ParseField("field");
|
|
|
+ private static final ParseField DOCUMENT_TYPE_FIELD = new ParseField("document_type");
|
|
|
+ private static final ParseField INDEXED_DOCUMENT_FIELD_TYPE = new ParseField("type");
|
|
|
private static final ParseField INDEXED_DOCUMENT_FIELD_INDEX = new ParseField("index");
|
|
|
private static final ParseField INDEXED_DOCUMENT_FIELD_ID = new ParseField("id");
|
|
|
private static final ParseField INDEXED_DOCUMENT_FIELD_ROUTING = new ParseField("routing");
|
|
@@ -287,6 +301,9 @@ public class PercolateQueryBuilder extends AbstractQueryBuilder<PercolateQueryBu
|
|
|
if (indexedDocumentIndex != null) {
|
|
|
builder.field(INDEXED_DOCUMENT_FIELD_INDEX.getPreferredName(), indexedDocumentIndex);
|
|
|
}
|
|
|
+ if (builder.getRestApiVersion() == RestApiVersion.V_7) {
|
|
|
+ builder.field(INDEXED_DOCUMENT_FIELD_TYPE.getPreferredName(), MapperService.SINGLE_MAPPING_NAME);
|
|
|
+ }
|
|
|
if (indexedDocumentId != null) {
|
|
|
builder.field(INDEXED_DOCUMENT_FIELD_ID.getPreferredName(), indexedDocumentId);
|
|
|
}
|
|
@@ -338,6 +355,14 @@ public class PercolateQueryBuilder extends AbstractQueryBuilder<PercolateQueryBu
|
|
|
DOCUMENTS_FIELD.getPreferredName(), INDEXED_DOCUMENT_FIELD_ID.getPreferredName());
|
|
|
PARSER.declareExclusiveFieldSet(DOCUMENT_FIELD.getPreferredName(),
|
|
|
DOCUMENTS_FIELD.getPreferredName(), INDEXED_DOCUMENT_FIELD_ID.getPreferredName());
|
|
|
+ PARSER.declareString(deprecateAndIgnoreType("percolate_with_type", TYPE_DEPRECATION_MESSAGE),
|
|
|
+ INDEXED_DOCUMENT_FIELD_TYPE.forRestApiVersion(equalTo(RestApiVersion.V_7)));
|
|
|
+ PARSER.declareString(deprecateAndIgnoreType("percolate_with_document_type", DOCUMENT_TYPE_DEPRECATION_MESSAGE),
|
|
|
+ DOCUMENT_TYPE_FIELD.forRestApiVersion(equalTo(RestApiVersion.V_7)));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static BiConsumer<PercolateQueryBuilder, String> deprecateAndIgnoreType(String key, String message) {
|
|
|
+ return (target, type) -> deprecationLogger.compatibleApiWarning(key, message);
|
|
|
}
|
|
|
|
|
|
private static BytesReference parseDocument(XContentParser parser) throws IOException {
|