diff --git a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index f33620a08712e..42f7ee109249b 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -92,23 +92,32 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder> SUPPORTED_FIELD_TYPES = new HashSet<>( Arrays.asList(TextFieldType.class, KeywordFieldType.class)); - private interface Field { - ParseField FIELDS = new ParseField("fields"); - ParseField LIKE = new ParseField("like"); - ParseField UNLIKE = new ParseField("unlike"); - ParseField MAX_QUERY_TERMS = new ParseField("max_query_terms"); - ParseField MIN_TERM_FREQ = new ParseField("min_term_freq"); - ParseField MIN_DOC_FREQ = new ParseField("min_doc_freq"); - ParseField MAX_DOC_FREQ = new ParseField("max_doc_freq"); - ParseField MIN_WORD_LENGTH = new ParseField("min_word_length"); - ParseField MAX_WORD_LENGTH = new ParseField("max_word_length"); - ParseField STOP_WORDS = new ParseField("stop_words"); - ParseField ANALYZER = new ParseField("analyzer"); - ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match"); - ParseField BOOST_TERMS = new ParseField("boost_terms"); - ParseField INCLUDE = new ParseField("include"); - ParseField FAIL_ON_UNSUPPORTED_FIELD = new ParseField("fail_on_unsupported_field"); - } + private static final ParseField FIELDS = new ParseField("fields"); + private static final ParseField LIKE = new ParseField("like"); + private static final ParseField UNLIKE = new ParseField("unlike"); + private static final ParseField MAX_QUERY_TERMS = new ParseField("max_query_terms"); + private static final ParseField MIN_TERM_FREQ = new ParseField("min_term_freq"); + private static final ParseField MIN_DOC_FREQ = new ParseField("min_doc_freq"); + private static final ParseField MAX_DOC_FREQ = new ParseField("max_doc_freq"); + private static final ParseField MIN_WORD_LENGTH = new ParseField("min_word_length"); + private static final ParseField MAX_WORD_LENGTH = new ParseField("max_word_length"); + private static final ParseField STOP_WORDS = new ParseField("stop_words"); + private static final ParseField ANALYZER = new ParseField("analyzer"); + private static final ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match"); + private static final ParseField BOOST_TERMS = new ParseField("boost_terms"); + private static final ParseField INCLUDE = new ParseField("include"); + private static final ParseField FAIL_ON_UNSUPPORTED_FIELD = new ParseField("fail_on_unsupported_field"); + + private static final ParseField INDEX = new ParseField("_index"); + private static final ParseField TYPE = new ParseField("_type"); + private static final ParseField ID = new ParseField("_id"); + public static final ParseField DOC = new ParseField("doc"); + private static final ParseField PER_FIELD_ANALYZER = new ParseField("per_field_analyzer"); + private static final ParseField ROUTING = new ParseField("routing","_routing"); + private static final ParseField VERSION = new ParseField("version","_version"); + private static final ParseField VERSION_TYPE = new ParseField("version_type", + "_version_type", "_versionType", "versionType"); + // document inputs private final String[] fields; @@ -141,19 +150,6 @@ private interface Field { public static final class Item implements ToXContentObject, Writeable { public static final Item[] EMPTY_ARRAY = new Item[0]; - public interface Field { - ParseField INDEX = new ParseField("_index"); - ParseField TYPE = new ParseField("_type"); - ParseField ID = new ParseField("_id"); - ParseField DOC = new ParseField("doc"); - ParseField FIELDS = new ParseField("fields"); - ParseField PER_FIELD_ANALYZER = new ParseField("per_field_analyzer"); - ParseField ROUTING = new ParseField("routing","_routing"); - ParseField VERSION = new ParseField("version","_version"); - ParseField VERSION_TYPE = new ParseField("version_type", - "_version_type", "_versionType", "versionType"); - } - private String index; private String type; private String id; @@ -371,16 +367,16 @@ public static Item parse(XContentParser parser, Item item) throws IOException { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (currentFieldName != null) { - if (Field.INDEX.match(currentFieldName)) { + if (INDEX.match(currentFieldName)) { item.index = parser.text(); - } else if (Field.TYPE.match(currentFieldName)) { + } else if (TYPE.match(currentFieldName)) { item.type = parser.text(); - } else if (Field.ID.match(currentFieldName)) { + } else if (ID.match(currentFieldName)) { item.id = parser.text(); - } else if (Field.DOC.match(currentFieldName)) { + } else if (DOC.match(currentFieldName)) { item.doc = jsonBuilder().copyCurrentStructure(parser).bytes(); item.xContentType = XContentType.JSON; - } else if (Field.FIELDS.match(currentFieldName)) { + } else if (FIELDS.match(currentFieldName)) { if (token == XContentParser.Token.START_ARRAY) { List fields = new ArrayList<>(); while (parser.nextToken() != XContentParser.Token.END_ARRAY) { @@ -391,13 +387,13 @@ public static Item parse(XContentParser parser, Item item) throws IOException { throw new ElasticsearchParseException( "failed to parse More Like This item. field [fields] must be an array"); } - } else if (Field.PER_FIELD_ANALYZER.match(currentFieldName)) { + } else if (PER_FIELD_ANALYZER.match(currentFieldName)) { item.perFieldAnalyzer(TermVectorsRequest.readPerFieldAnalyzer(parser.map())); - } else if (Field.ROUTING.match(currentFieldName)) { + } else if (ROUTING.match(currentFieldName)) { item.routing = parser.text(); - } else if (Field.VERSION.match(currentFieldName)) { + } else if (VERSION.match(currentFieldName)) { item.version = parser.longValue(); - } else if (Field.VERSION_TYPE.match(currentFieldName)) { + } else if (VERSION_TYPE.match(currentFieldName)) { item.versionType = VersionType.fromString(parser.text()); } else { throw new ElasticsearchParseException( @@ -420,31 +416,31 @@ public static Item parse(XContentParser parser, Item item) throws IOException { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (this.index != null) { - builder.field(Field.INDEX.getPreferredName(), this.index); + builder.field(INDEX.getPreferredName(), this.index); } if (this.type != null) { - builder.field(Field.TYPE.getPreferredName(), this.type); + builder.field(TYPE.getPreferredName(), this.type); } if (this.id != null) { - builder.field(Field.ID.getPreferredName(), this.id); + builder.field(ID.getPreferredName(), this.id); } if (this.doc != null) { - builder.rawField(Field.DOC.getPreferredName(), this.doc, xContentType); + builder.rawField(DOC.getPreferredName(), this.doc, xContentType); } if (this.fields != null) { - builder.array(Field.FIELDS.getPreferredName(), this.fields); + builder.array(FIELDS.getPreferredName(), this.fields); } if (this.perFieldAnalyzer != null) { - builder.field(Field.PER_FIELD_ANALYZER.getPreferredName(), this.perFieldAnalyzer); + builder.field(PER_FIELD_ANALYZER.getPreferredName(), this.perFieldAnalyzer); } if (this.routing != null) { - builder.field(Field.ROUTING.getPreferredName(), this.routing); + builder.field(ROUTING.getPreferredName(), this.routing); } if (this.version != Versions.MATCH_ANY) { - builder.field(Field.VERSION.getPreferredName(), this.version); + builder.field(VERSION.getPreferredName(), this.version); } if (this.versionType != VersionType.INTERNAL) { - builder.field(Field.VERSION_TYPE.getPreferredName(), this.versionType.toString().toLowerCase(Locale.ROOT)); + builder.field(VERSION_TYPE.getPreferredName(), this.versionType.toString().toLowerCase(Locale.ROOT)); } return builder.endObject(); } @@ -781,26 +777,26 @@ public static Item[] ids(String... ids) { protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NAME); if (fields != null) { - builder.array(Field.FIELDS.getPreferredName(), fields); - } - buildLikeField(builder, Field.LIKE.getPreferredName(), likeTexts, likeItems); - buildLikeField(builder, Field.UNLIKE.getPreferredName(), unlikeTexts, unlikeItems); - builder.field(Field.MAX_QUERY_TERMS.getPreferredName(), maxQueryTerms); - builder.field(Field.MIN_TERM_FREQ.getPreferredName(), minTermFreq); - builder.field(Field.MIN_DOC_FREQ.getPreferredName(), minDocFreq); - builder.field(Field.MAX_DOC_FREQ.getPreferredName(), maxDocFreq); - builder.field(Field.MIN_WORD_LENGTH.getPreferredName(), minWordLength); - builder.field(Field.MAX_WORD_LENGTH.getPreferredName(), maxWordLength); + builder.array(FIELDS.getPreferredName(), fields); + } + buildLikeField(builder, LIKE.getPreferredName(), likeTexts, likeItems); + buildLikeField(builder, UNLIKE.getPreferredName(), unlikeTexts, unlikeItems); + builder.field(MAX_QUERY_TERMS.getPreferredName(), maxQueryTerms); + builder.field(MIN_TERM_FREQ.getPreferredName(), minTermFreq); + builder.field(MIN_DOC_FREQ.getPreferredName(), minDocFreq); + builder.field(MAX_DOC_FREQ.getPreferredName(), maxDocFreq); + builder.field(MIN_WORD_LENGTH.getPreferredName(), minWordLength); + builder.field(MAX_WORD_LENGTH.getPreferredName(), maxWordLength); if (stopWords != null) { - builder.array(Field.STOP_WORDS.getPreferredName(), stopWords); + builder.array(STOP_WORDS.getPreferredName(), stopWords); } if (analyzer != null) { - builder.field(Field.ANALYZER.getPreferredName(), analyzer); + builder.field(ANALYZER.getPreferredName(), analyzer); } - builder.field(Field.MINIMUM_SHOULD_MATCH.getPreferredName(), minimumShouldMatch); - builder.field(Field.BOOST_TERMS.getPreferredName(), boostTerms); - builder.field(Field.INCLUDE.getPreferredName(), include); - builder.field(Field.FAIL_ON_UNSUPPORTED_FIELD.getPreferredName(), failOnUnsupportedField); + builder.field(MINIMUM_SHOULD_MATCH.getPreferredName(), minimumShouldMatch); + builder.field(BOOST_TERMS.getPreferredName(), boostTerms); + builder.field(INCLUDE.getPreferredName(), include); + builder.field(FAIL_ON_UNSUPPORTED_FIELD.getPreferredName(), failOnUnsupportedField); printBoostAndQueryName(builder); builder.endObject(); } @@ -839,31 +835,31 @@ public static MoreLikeThisQueryBuilder fromXContent(XContentParser parser) throw if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (Field.LIKE.match(currentFieldName)) { + if (LIKE.match(currentFieldName)) { parseLikeField(parser, likeTexts, likeItems); - } else if (Field.UNLIKE.match(currentFieldName)) { + } else if (UNLIKE.match(currentFieldName)) { parseLikeField(parser, unlikeTexts, unlikeItems); - } else if (Field.MAX_QUERY_TERMS.match(currentFieldName)) { + } else if (MAX_QUERY_TERMS.match(currentFieldName)) { maxQueryTerms = parser.intValue(); - } else if (Field.MIN_TERM_FREQ.match(currentFieldName)) { + } else if (MIN_TERM_FREQ.match(currentFieldName)) { minTermFreq =parser.intValue(); - } else if (Field.MIN_DOC_FREQ.match(currentFieldName)) { + } else if (MIN_DOC_FREQ.match(currentFieldName)) { minDocFreq = parser.intValue(); - } else if (Field.MAX_DOC_FREQ.match(currentFieldName)) { + } else if (MAX_DOC_FREQ.match(currentFieldName)) { maxDocFreq = parser.intValue(); - } else if (Field.MIN_WORD_LENGTH.match(currentFieldName)) { + } else if (MIN_WORD_LENGTH.match(currentFieldName)) { minWordLength = parser.intValue(); - } else if (Field.MAX_WORD_LENGTH.match(currentFieldName)) { + } else if (MAX_WORD_LENGTH.match(currentFieldName)) { maxWordLength = parser.intValue(); - } else if (Field.ANALYZER.match(currentFieldName)) { + } else if (ANALYZER.match(currentFieldName)) { analyzer = parser.text(); - } else if (Field.MINIMUM_SHOULD_MATCH.match(currentFieldName)) { + } else if (MINIMUM_SHOULD_MATCH.match(currentFieldName)) { minimumShouldMatch = parser.text(); - } else if (Field.BOOST_TERMS.match(currentFieldName)) { + } else if (BOOST_TERMS.match(currentFieldName)) { boostTerms = parser.floatValue(); - } else if (Field.INCLUDE.match(currentFieldName)) { + } else if (INCLUDE.match(currentFieldName)) { include = parser.booleanValue(); - } else if (Field.FAIL_ON_UNSUPPORTED_FIELD.match(currentFieldName)) { + } else if (FAIL_ON_UNSUPPORTED_FIELD.match(currentFieldName)) { failOnUnsupportedField = parser.booleanValue(); } else if ("boost".equals(currentFieldName)) { boost = parser.floatValue(); @@ -873,20 +869,20 @@ public static MoreLikeThisQueryBuilder fromXContent(XContentParser parser) throw throw new ParsingException(parser.getTokenLocation(), "[mlt] query does not support [" + currentFieldName + "]"); } } else if (token == XContentParser.Token.START_ARRAY) { - if (Field.FIELDS.match(currentFieldName)) { + if (FIELDS.match(currentFieldName)) { fields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { fields.add(parser.text()); } - } else if (Field.LIKE.match(currentFieldName)) { + } else if (LIKE.match(currentFieldName)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { parseLikeField(parser, likeTexts, likeItems); } - } else if (Field.UNLIKE.match(currentFieldName)) { + } else if (UNLIKE.match(currentFieldName)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { parseLikeField(parser, unlikeTexts, unlikeItems); } - } else if (Field.STOP_WORDS.match(currentFieldName)) { + } else if (STOP_WORDS.match(currentFieldName)) { stopWords = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { stopWords.add(parser.text()); @@ -895,9 +891,9 @@ public static MoreLikeThisQueryBuilder fromXContent(XContentParser parser) throw throw new ParsingException(parser.getTokenLocation(), "[mlt] query does not support [" + currentFieldName + "]"); } } else if (token == XContentParser.Token.START_OBJECT) { - if (Field.LIKE.match(currentFieldName)) { + if (LIKE.match(currentFieldName)) { parseLikeField(parser, likeTexts, likeItems); - } else if (Field.UNLIKE.match(currentFieldName)) { + } else if (UNLIKE.match(currentFieldName)) { parseLikeField(parser, unlikeTexts, unlikeItems); } else { throw new ParsingException(parser.getTokenLocation(), "[mlt] query does not support [" + currentFieldName + "]"); diff --git a/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java index 4f7e461ecaa63..922aa9a682f45 100644 --- a/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java @@ -67,7 +67,7 @@ public class MoreLikeThisQueryBuilderTests extends AbstractQueryTestCase { - private static final String[] SHUFFLE_PROTECTED_FIELDS = new String[]{Item.Field.DOC.getPreferredName()}; + private static final String[] SHUFFLE_PROTECTED_FIELDS = new String[]{MoreLikeThisQueryBuilder.DOC.getPreferredName()}; private static String[] randomFields; private static Item[] randomLikeItems; @@ -222,7 +222,7 @@ protected String[] shuffleProtectedFields() { @Override protected Set getObjectsHoldingArbitraryContent() { //doc contains arbitrary content, anything can be added to it and no exception will be thrown - return Collections.singleton(MoreLikeThisQueryBuilder.Item.Field.DOC.getPreferredName()); + return Collections.singleton(MoreLikeThisQueryBuilder.DOC.getPreferredName()); } @Override diff --git a/docs/reference/docs/bulk.asciidoc b/docs/reference/docs/bulk.asciidoc index b932e2466216f..6c90df9de4021 100644 --- a/docs/reference/docs/bulk.asciidoc +++ b/docs/reference/docs/bulk.asciidoc @@ -201,16 +201,16 @@ chunks, as this will slow things down. === Versioning Each bulk item can include the version value using the -`_version`/`version` field. It automatically follows the behavior of the +`version` field. It automatically follows the behavior of the index / delete operation based on the `_version` mapping. It also -support the `version_type`/`_version_type` (see <>) +support the `version_type` (see <>) [float] [[bulk-routing]] === Routing Each bulk item can include the routing value using the -`_routing`/`routing` field. It automatically follows the behavior of the +`routing` field. It automatically follows the behavior of the index / delete operation based on the `_routing` mapping. [float] @@ -234,7 +234,7 @@ Control when the changes made by this request are visible to search. See [[bulk-update]] === Update -When using `update` action `_retry_on_conflict` can be used as field in +When using `update` action `retry_on_conflict` can be used as field in the action itself (not in the extra payload line), to specify how many times an update should be retried in the case of a version conflict. @@ -246,11 +246,11 @@ the options. Example with update actions: [source,js] -------------------------------------------------- POST _bulk -{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1", "_retry_on_conflict" : 3} } +{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1", "retry_on_conflict" : 3} } { "doc" : {"field" : "value"} } -{ "update" : { "_id" : "0", "_type" : "type1", "_index" : "index1", "_retry_on_conflict" : 3} } +{ "update" : { "_id" : "0", "_type" : "type1", "_index" : "index1", "retry_on_conflict" : 3} } { "script" : { "source": "ctx._source.counter += params.param1", "lang" : "painless", "params" : {"param1" : 1}}, "upsert" : {"counter" : 1}} -{ "update" : {"_id" : "2", "_type" : "type1", "_index" : "index1", "_retry_on_conflict" : 3} } +{ "update" : {"_id" : "2", "_type" : "type1", "_index" : "index1", "retry_on_conflict" : 3} } { "doc" : {"field" : "value"}, "doc_as_upsert" : true } { "update" : {"_id" : "3", "_type" : "type1", "_index" : "index1", "_source" : true} } { "doc" : {"field" : "value"} } diff --git a/docs/reference/docs/multi-get.asciidoc b/docs/reference/docs/multi-get.asciidoc index 6940fe8319cc6..b241607f85369 100644 --- a/docs/reference/docs/multi-get.asciidoc +++ b/docs/reference/docs/multi-get.asciidoc @@ -230,7 +230,7 @@ GET /_mget?routing=key1 "_index" : "test", "_type" : "type", "_id" : "1", - "_routing" : "key2" + "routing" : "key2" }, { "_index" : "test", diff --git a/qa/mixed-cluster/src/test/java/org/elasticsearch/backwards/IndexingIT.java b/qa/mixed-cluster/src/test/java/org/elasticsearch/backwards/IndexingIT.java index e788983cc5057..f744b3029b125 100644 --- a/qa/mixed-cluster/src/test/java/org/elasticsearch/backwards/IndexingIT.java +++ b/qa/mixed-cluster/src/test/java/org/elasticsearch/backwards/IndexingIT.java @@ -248,7 +248,7 @@ private void assertVersion(final String index, final int docId, final String pre final Response response = client().performRequest("GET", index + "/test/" + docId, Collections.singletonMap("preference", preference)); assertOK(response); - final int actualVersion = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("version").toString()); + final int actualVersion = Integer.parseInt(ObjectPath.createFromResponse(response).evaluate("_version").toString()); assertThat("version mismatch for doc [" + docId + "] preference [" + preference + "]", actualVersion, equalTo(expectedVersion)); } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/mtermvectors/20_deprecated.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/mtermvectors/20_deprecated.yml new file mode 100644 index 0000000000000..9f4bbe2b24c78 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/mtermvectors/20_deprecated.yml @@ -0,0 +1,95 @@ + +--- +"Deprecated parameters should produce warning in Term Vectors query": + + - skip: + version: " - 6.99.99" + reason: versionType, _version_type are deprecated starting from 7.0, version_type is used instead + features: "warnings" + + - do: + indices.create: + index: testidx + body: + mappings: + testtype: + properties: + text: + type : "text" + term_vector : "with_positions_offsets" + + - do: + index: + index: testidx + type: testtype + id: testing_document + body: {"text" : "The quick brown fox is brown."} + + - do: + mtermvectors: + "term_statistics" : true + "body" : + "docs": + - + "_index" : "testidx" + "_type" : "testtype" + "_id" : "testing_document" + "version" : 1 + "versionType" : "external" + warnings: + - "Deprecated field [versionType] used, expected [version_type] instead" + + - do: + mtermvectors: + "term_statistics" : true + "body" : + "docs": + - + "_index" : "testidx" + "_type" : "testtype" + "_id" : "testing_document" + "version" : 1 + "_version_type" : "external" + warnings: + - "Deprecated field [_version_type] used, expected [version_type] instead" + + + +--- +"Deprecated camel case parameters should fail in Term Vectors query": + + - skip: + version: " - 7.99.99" + reason: camel case parameters such as version_type should fail starting from 8.0 + features: "warnings" + + - do: + indices.create: + index: testidx + body: + mappings: + testtype: + properties: + text: + type : "text" + term_vector : "with_positions_offsets" + + - do: + index: + index: testidx + type: testtype + id: testing_document + body: {"text" : "The quick brown fox is brown."} + + - do: + catch: bad_request + mtermvectors: + "term_statistics" : true + "body" : + "docs": + - + "_index" : "testidx" + "_type" : "testtype" + "_id" : "testing_document" + "version" : 1 + "versionType" : "external"