Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate reference to _type in lookup queries #37016

Merged
Show file tree
Hide file tree
Changes from 2 commits
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 @@ -875,7 +875,7 @@ public void testUpdateByQuery() throws Exception {
// test1: create one doc in dest
UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest();
updateByQueryRequest.indices(sourceIndex);
updateByQueryRequest.setQuery(new IdsQueryBuilder().addIds("1").types("_doc"));
updateByQueryRequest.setQuery(new IdsQueryBuilder().addIds("1"));
updateByQueryRequest.setRefresh(true);
BulkByScrollResponse bulkResponse =
execute(updateByQueryRequest, highLevelClient()::updateByQuery, highLevelClient()::updateByQueryAsync);
Expand Down Expand Up @@ -917,7 +917,7 @@ public void testUpdateByQuery() throws Exception {
// test update-by-query rethrottling
UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest();
updateByQueryRequest.indices(sourceIndex);
updateByQueryRequest.setQuery(new IdsQueryBuilder().addIds("1").types("_doc"));
updateByQueryRequest.setQuery(new IdsQueryBuilder().addIds("1"));
updateByQueryRequest.setRefresh(true);

// this following settings are supposed to halt reindexing after first document
Expand Down Expand Up @@ -987,7 +987,7 @@ public void testDeleteByQuery() throws Exception {
// test1: delete one doc
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest();
deleteByQueryRequest.indices(sourceIndex);
deleteByQueryRequest.setQuery(new IdsQueryBuilder().addIds("1").types("_doc"));
deleteByQueryRequest.setQuery(new IdsQueryBuilder().addIds("1"));
deleteByQueryRequest.setRefresh(true);
BulkByScrollResponse bulkResponse =
execute(deleteByQueryRequest, highLevelClient()::deleteByQuery, highLevelClient()::deleteByQueryAsync);
Expand All @@ -1009,7 +1009,7 @@ public void testDeleteByQuery() throws Exception {
// test delete-by-query rethrottling
DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest();
deleteByQueryRequest.indices(sourceIndex);
deleteByQueryRequest.setQuery(new IdsQueryBuilder().addIds("2", "3").types("_doc"));
deleteByQueryRequest.setQuery(new IdsQueryBuilder().addIds("2", "3"));
deleteByQueryRequest.setRefresh(true);

// this following settings are supposed to halt reindexing after first document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,10 @@ public void testGeoShape() throws IOException {
// Using pre-indexed shapes
GeoShapeQueryBuilder qb = geoShapeQuery(
"pin.location", // <1>
"DEU", // <2>
"countries"); // <3>
qb.relation(ShapeRelation.WITHIN) // <4>
.indexedShapeIndex("shapes") // <5>
.indexedShapePath("location"); // <6>
"DEU"); // <2>
qb.relation(ShapeRelation.WITHIN) // <3>
.indexedShapeIndex("shapes") // <4>
.indexedShapePath("location"); // <5>
// end::indexed_geo_shape
}
}
Expand All @@ -236,9 +235,6 @@ public void testHasParent() {

public void testIds() {
// tag::ids
idsQuery("my_type", "type2")
.addIds("1", "4", "100");

idsQuery() // <1>
.addIds("1", "4", "100");
// end::ids
Expand Down
7 changes: 3 additions & 4 deletions docs/java-api/query-dsl/geo-shape-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ include-tagged::{query-dsl-test}[indexed_geo_shape]
--------------------------------------------------
<1> field
<2> The ID of the document that containing the pre-indexed shape.
<3> Index type where the pre-indexed shape is.
<4> relation
<5> Name of the index where the pre-indexed shape is. Defaults to 'shapes'.
<6> The field specified as path containing the pre-indexed shape. Defaults to 'shape'.
<3> relation
<4> Name of the index where the pre-indexed shape is. Defaults to 'shapes'.
<5> The field specified as path containing the pre-indexed shape. Defaults to 'shape'.
1 change: 0 additions & 1 deletion docs/java-api/query-dsl/ids-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ See {ref}/query-dsl-ids-query.html[Ids Query]
--------------------------------------------------
include-tagged::{query-dsl-test}[ids]
--------------------------------------------------
<1> type is optional
4 changes: 1 addition & 3 deletions docs/reference/query-dsl/geo-shape-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ GET /example/_search
==== Pre-Indexed Shape

The Query also supports using a shape which has already been indexed in
another index and/or index type. This is particularly useful for when
another index. This is particularly useful for when
you have a pre-defined list of shapes which are useful to your
application and you want to reference this using a logical name (for
example 'New Zealand') rather than having to provide their coordinates
Expand All @@ -90,7 +90,6 @@ each time. In this situation it is only necessary to provide:
* `id` - The ID of the document that containing the pre-indexed shape.
* `index` - Name of the index where the pre-indexed shape is. Defaults
to 'shapes'.
* `type` - Index type where the pre-indexed shape is.
* `path` - The field specified as path containing the pre-indexed shape.
Defaults to 'shape'.
* `routing` - The routing of the shape document if required.
Expand Down Expand Up @@ -130,7 +129,6 @@ GET /example/_search
"location": {
"indexed_shape": {
"index": "shapes",
"type": "_doc",
"id": "deu",
"path": "location"
}
Expand Down
4 changes: 0 additions & 4 deletions docs/reference/query-dsl/ids-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ GET /_search
{
"query": {
"ids" : {
"type" : "_doc",
"values" : ["1", "4", "100"]
}
}
}
--------------------------------------------------
// CONSOLE

The `type` is optional and can be omitted, and can also accept an array
of values. If no type is specified, all types defined in the index mapping are tried.
4 changes: 0 additions & 4 deletions docs/reference/query-dsl/mlt-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ GET /_search
"like" : [
{
"_index" : "imdb",
"_type" : "movies",
"_id" : "1"
},
{
"_index" : "imdb",
"_type" : "movies",
"_id" : "2"
},
"and potentially some more text here as well"
Expand All @@ -74,7 +72,6 @@ GET /_search
"like" : [
{
"_index" : "marvel",
"_type" : "quotes",
"doc" : {
"name": {
"first": "Ben",
Expand All @@ -85,7 +82,6 @@ GET /_search
},
{
"_index" : "marvel",
"_type" : "quotes",
"_id" : "2"
}
],
Expand Down
4 changes: 0 additions & 4 deletions docs/reference/query-dsl/terms-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ The terms lookup mechanism supports the following options:
`index`::
The index to fetch the term values from.

`type`::
The type to fetch the term values from.

`id`::
The id of the document to fetch the term values from.

Expand Down Expand Up @@ -93,7 +90,6 @@ GET /tweets/_search
"terms" : {
"user" : {
"index" : "users",
"type" : "_doc",
"id" : "2",
"path" : "followers"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public void testStoringQueries() throws Exception {
public void testQueryWithRewrite() throws Exception {
addQueryFieldMappings();
client().prepareIndex("remote", "doc", "1").setSource("field", "value").get();
QueryBuilder queryBuilder = termsLookupQuery("field", new TermsLookup("remote", "doc", "1", "field"));
QueryBuilder queryBuilder = termsLookupQuery("field", new TermsLookup("remote", "1", "field"));
ParsedDocument doc = mapperService.documentMapper("doc").parse(new SourceToParse("test", "doc", "1",
BytesReference.bytes(XContentFactory
.jsonBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
search:
rest_total_hits_as_int: true
index: test_index
body: {"query" : {"terms" : {"user" : {"index" : "test_index", "type" : "test_type", "id" : "u1", "path" : "followers"}}}}
body: {"query" : {"terms" : {"user" : {"index" : "test_index", "id" : "u1", "path" : "followers"}}}}
- match: { hits.total: 2 }

- do:
catch: bad_request
search:
rest_total_hits_as_int: true
index: test_index
body: {"query" : {"terms" : {"user" : {"index" : "test_index", "type" : "test_type", "id" : "u2", "path" : "followers"}}}}
body: {"query" : {"terms" : {"user" : {"index" : "test_index", "id" : "u2", "path" : "followers"}}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
"Terms Query with No.of terms exceeding index.max_terms_count should FAIL":
- skip:
version: " - 6.99.99"
reason: index.max_terms_count setting has been added in 7.0.0
- do:
indices.create:
index: test_index
body:
settings:
number_of_shards: 1
index.max_terms_count: 2
mappings:
test_type:
properties:
user:
type: keyword
followers:
type: keyword
- do:
bulk:
refresh: true
body:
- '{"index": {"_index": "test_index", "_type": "test_type", "_id": "u1"}}'
- '{"user": "u1", "followers": ["u2", "u3"]}'
- '{"index": {"_index": "test_index", "_type": "test_type", "_id": "u2"}}'
- '{"user": "u2", "followers": ["u1", "u3", "u4"]}'
- '{"index": {"_index": "test_index", "_type": "test_type", "_id": "u3"}}'
- '{"user": "u3", "followers": ["u1"]}'
- '{"index": {"_index": "test_index", "_type": "test_type", "_id": "u4"}}'
- '{"user": "u4", "followers": ["u3"]}'

- do:
search:
rest_total_hits_as_int: true
index: test_index
body: {"query" : {"terms" : {"user" : ["u1", "u2"]}}}
- match: { hits.total: 2 }

- do:
catch: bad_request
search:
rest_total_hits_as_int: true
index: test_index
body: {"query" : {"terms" : {"user" : ["u1", "u2", "u3"]}}}

- do:
search:
rest_total_hits_as_int: true
index: test_index
body: {"query" : {"terms" : {"user" : {"index" : "test_index", "type" : "test_type", "id" : "u1", "path" : "followers"}}}}
- match: { hits.total: 2 }

- do:
catch: bad_request
search:
rest_total_hits_as_int: true
index: test_index
body: {"query" : {"terms" : {"user" : {"index" : "test_index", "type" : "test_type", "id" : "u2", "path" : "followers"}}}}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.index.query;

import org.apache.logging.log4j.LogManager;
import org.apache.lucene.document.LatLonShape;
import org.apache.lucene.geo.Line;
import org.apache.lucene.geo.Polygon;
Expand All @@ -38,6 +39,7 @@
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.geo.GeoPoint;
Expand All @@ -48,6 +50,7 @@
import org.elasticsearch.common.geo.parsers.ShapeParser;
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.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
import org.elasticsearch.common.xcontent.XContentBuilder;
Expand All @@ -66,6 +69,10 @@
*/
public class GeoShapeQueryBuilder extends AbstractQueryBuilder<GeoShapeQueryBuilder> {
public static final String NAME = "geo_shape";
private static final DeprecationLogger deprecationLogger = new DeprecationLogger(
LogManager.getLogger(GeoShapeQueryBuilder.class));
static final String TYPES_DEPRECATION_MESSAGE = "[types removal] Types are deprecated in [geo_shape] queries. " +
"The type should no longer be specified in the [indexed_shape] section.";

public static final String DEFAULT_SHAPE_INDEX_NAME = "shapes";
public static final String DEFAULT_SHAPE_FIELD_NAME = "shape";
Expand Down Expand Up @@ -119,6 +126,19 @@ public GeoShapeQueryBuilder(String fieldName, ShapeBuilder shape) {
this(fieldName, shape, null, null);
}

/**
* Creates a new GeoShapeQueryBuilder whose Query will be against the given
* field name and will use the Shape found with the given ID
*
* @param fieldName
* Name of the field that will be filtered
* @param indexedShapeId
* ID of the indexed Shape that will be used in the Query
*/
public GeoShapeQueryBuilder(String fieldName, String indexedShapeId) {
this(fieldName, (ShapeBuilder) null, indexedShapeId, null);
}

/**
* Creates a new GeoShapeQueryBuilder whose Query will be against the given
* field name and will use the Shape found with the given ID in the given
Expand All @@ -130,20 +150,19 @@ public GeoShapeQueryBuilder(String fieldName, ShapeBuilder shape) {
* ID of the indexed Shape that will be used in the Query
* @param indexedShapeType
* Index type of the indexed Shapes
* @deprecated use {@link #GeoShapeQueryBuilder(String, String)} instead
*/
@Deprecated
public GeoShapeQueryBuilder(String fieldName, String indexedShapeId, String indexedShapeType) {
this(fieldName, (ShapeBuilder) null, indexedShapeId, indexedShapeType);
}

private GeoShapeQueryBuilder(String fieldName, ShapeBuilder shape, String indexedShapeId, String indexedShapeType) {
private GeoShapeQueryBuilder(String fieldName, ShapeBuilder shape, String indexedShapeId, @Nullable String indexedShapeType) {
if (fieldName == null) {
throw new IllegalArgumentException("fieldName is required");
}
if (shape == null && indexedShapeId == null) {
throw new IllegalArgumentException("either shapeBytes or indexedShapeId and indexedShapeType are required");
}
if (indexedShapeId != null && indexedShapeType == null) {
throw new IllegalArgumentException("indexedShapeType is required if indexedShapeId is specified");
throw new IllegalArgumentException("either shapeBytes or indexedShapeId is required");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"shapeBytes" should be "shape"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
this.fieldName = fieldName;
this.shape = shape;
Expand All @@ -152,7 +171,8 @@ private GeoShapeQueryBuilder(String fieldName, ShapeBuilder shape, String indexe
this.supplier = null;
}

private GeoShapeQueryBuilder(String fieldName, Supplier<ShapeBuilder> supplier, String indexedShapeId, String indexedShapeType) {
private GeoShapeQueryBuilder(String fieldName, Supplier<ShapeBuilder> supplier, String indexedShapeId,
@Nullable String indexedShapeType) {
this.fieldName = fieldName;
this.shape = null;
this.supplier = supplier;
Expand Down Expand Up @@ -239,6 +259,7 @@ public String indexedShapeId() {
* @return the document type of the indexed Shape that will be used in the
* Query
*/
@Deprecated
public String indexedShapeType() {
return indexedShapeType;
}
Expand Down Expand Up @@ -566,8 +587,10 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep
shape.toXContent(builder, params);
} else {
builder.startObject(INDEXED_SHAPE_FIELD.getPreferredName())
.field(SHAPE_ID_FIELD.getPreferredName(), indexedShapeId)
.field(SHAPE_TYPE_FIELD.getPreferredName(), indexedShapeType);
.field(SHAPE_ID_FIELD.getPreferredName(), indexedShapeId);
if (indexedShapeType != null) {
builder.field(SHAPE_TYPE_FIELD.getPreferredName(), indexedShapeType);
}
if (indexedShapeIndex != null) {
builder.field(SHAPE_INDEX_FIELD.getPreferredName(), indexedShapeIndex);
}
Expand Down Expand Up @@ -677,6 +700,11 @@ public static GeoShapeQueryBuilder fromXContent(XContentParser parser) throws IO
}
}
GeoShapeQueryBuilder builder;
if (type != null) {
deprecationLogger.deprecatedAndMaybeLog(
"geo_share_query_with_types", TYPES_DEPRECATION_MESSAGE);
}

if (shape != null) {
builder = new GeoShapeQueryBuilder(fieldName, shape);
} else {
Expand Down Expand Up @@ -739,7 +767,12 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
} else if (this.shape == null) {
SetOnce<ShapeBuilder> supplier = new SetOnce<>();
queryRewriteContext.registerAsyncAction((client, listener) -> {
GetRequest getRequest = new GetRequest(indexedShapeIndex, indexedShapeType, indexedShapeId);
GetRequest getRequest;
if (indexedShapeType == null) {
getRequest = new GetRequest(indexedShapeIndex, indexedShapeId);
} else {
getRequest = new GetRequest(indexedShapeIndex, indexedShapeType, indexedShapeId);
}
getRequest.routing(indexedShapeRouting);
fetch(client, getRequest, indexedShapePath, ActionListener.wrap(builder-> {
supplier.set(builder);
Expand Down
Loading