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

Mappings: Deprecate index_name. #7057

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions docs/reference/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ include::setup.asciidoc[]

include::migration/migrate_1_0.asciidoc[]

include::migration/migrate_1_x.asciidoc[]

include::api-conventions.asciidoc[]

include::docs.asciidoc[]
Expand Down
15 changes: 6 additions & 9 deletions docs/reference/indices/get-field-mapping.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ You can also use wildcards. The field names can be any of the following:
[horizontal]
Full names:: the full path, including any parent object name the field is
part of (ex. `user.id`).
Index names:: the name of the lucene field (can be different than the
field name if the `index_name` option of the mapping is used).
Field names:: the name of the field without the path to it (ex. `id` for `{ "user" : { "id" : 1 } }`).

The above options are specified in the order the `field` parameter is resolved.
Expand All @@ -76,21 +74,20 @@ For example, consider the following mapping:
"article": {
"properties": {
"id": { "type": "string" },
"title": { "type": "string", "index_name": "text" },
"abstract": { "type": "string", "index_name": "text" },
"title": { "type": "string" },
"abstract": { "type": "string" },
"author": {
"properties": {
"id": { "type": "string" },
"name": { "type": "string", "index_name": "author" }
"name": { "type": "string" }
}
}
}
}
}
--------------------------------------------------

To select the `id` of the `author` field, you can use its full name `author.id`. Using `text` will return
the mapping of `abstract` as it is one of the fields which map to the Lucene field `text`. `name` will return
To select the `id` of the `author` field, you can use its full name `author.id`. `name` will return
the field `author.name`:

[source,js]
Expand All @@ -108,7 +105,7 @@ returns:
"text": {
"full_name": "abstract",
"mapping": {
"abstract": { "type": "string", "index_name": "text" }
"abstract": { "type": "string" }
}
},
"author.id": {
Expand All @@ -120,7 +117,7 @@ returns:
"name": {
"full_name": "author.name",
"mapping": {
"name": { "type": "string", "index_name": "author" }
"name": { "type": "string", }
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions docs/reference/mapping/types/array-type.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ is a sample explicit mapping:
"tweet" : {
"properties" : {
"message" : {"type" : "string"},
"tags" : {"type" : "string", "index_name" : "tag"},
"tags" : {"type" : "string"},
"lists" : {
"properties" : {
"name" : {"type" : "string"},
Expand Down Expand Up @@ -67,8 +67,3 @@ the fact that the following JSON document is perfectly fine:
}
--------------------------------------------------

Note also, that thanks to the fact that we used the `index_name` to use
the non plural form (`tag` instead of `tags`), we can actually refer to
the field using the `index_name` as well. For example, we can execute a
query using `tweet.tags:wow` or `tweet.tag:wow`. We could, of course,
name the field as `tag` and skip the `index_name` all together).
17 changes: 0 additions & 17 deletions docs/reference/mapping/types/core-types.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ The following table lists all the attributes that can be used with the
[cols="<,<",options="header",]
|=======================================================================
|Attribute |Description
|`index_name` |The name of the field that will be stored in the index.
Defaults to the property/field name.

|`store` |Set to `true` to actually store the field in the index, `false` to not
store it. Defaults to `false` (note, the JSON document itself is stored,
and it can be retrieved from it).
Expand Down Expand Up @@ -223,9 +220,6 @@ numbered type:
|`type` |The type of the number. Can be `float`, `double`, `integer`,
`long`, `short`, `byte`. Required.

|`index_name` |The name of the field that will be stored in the index.
Defaults to the property/field name.

|`store` |Set to `true` to store actual field in the index, `false` to not
store it. Defaults to `false` (note, the JSON document itself is stored,
and it can be retrieved from it).
Expand Down Expand Up @@ -330,9 +324,6 @@ date type:
[cols="<,<",options="header",]
|=======================================================================
|Attribute |Description
|`index_name` |The name of the field that will be stored in the index.
Defaults to the property/field name.

|`format` |The <<mapping-date-format,date
format>>. Defaults to `dateOptionalTime`.

Expand Down Expand Up @@ -396,9 +387,6 @@ boolean type:
[cols="<,<",options="header",]
|=======================================================================
|Attribute |Description
|`index_name` |The name of the field that will be stored in the index.
Defaults to the property/field name.

|`store` |Set to `true` to store actual field in the index, `false` to not
store it. Defaults to `false` (note, the JSON document itself is stored,
and it can be retrieved from it).
Expand Down Expand Up @@ -441,11 +429,6 @@ binary type:

[horizontal]

`index_name`::

The name of the field that will be stored in the index. Defaults to the
property/field name.

`store`::

Set to `true` to store actual field in the index, `false` to not store it.
Expand Down
3 changes: 0 additions & 3 deletions docs/reference/mapping/types/ip-type.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ type:
[cols="<,<",options="header",]
|=======================================================================
|Attribute |Description
|`index_name` |The name of the field that will be stored in the index.
Defaults to the property/field name.

|`store` |Set to `true` to store actual field in the index, `false` to not
store it. Defaults to `false` (note, the JSON document itself is stored,
and it can be retrieved from it).
Expand Down
37 changes: 37 additions & 0 deletions docs/reference/migration/migrate_1_x.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[[breaking-minor-changes]]
Copy link
Member

Choose a reason for hiding this comment

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

+1 I like this separate 1.x migrate page!

= Breaking changes between 1.x releases

[partintro]
--
This section discusses the changes that you need to be aware of when migrating
your application from Elasticsearch 1.x to Elasticsearch 1.y.
--

== Facets

Facets are deprecated and will be removed in a future release. You are
encouraged to migrate to <<search-aggregations, aggregations>> instead.

== 1.4.0

=== Index names

As of Elasticsearch 1.4.0, custom `index_name` are not supported anymore.
Indices that have been created prior to Elasticsearch 1.4.0 will still be
allowed to add or modify mappings with custom index names, but indices
that are created on an Elasticsearch version that is greater than or equal
to 1.4.0 will not.

When custom `index_name` were used to store the content of several fields
into a single index field, it is recommended to use the
<<copy-to,`copy_to`>> feature instead.

See https://github.com/elasticsearch/elasticsearch/issues/6677[#6677] for more
information.

=== path: just_name

`path: just_name` is deprecated since Elasticsearch 1.0 and will not be
supported on indices created on or after Elasticsearch 1.4.0.

It is recommended to use the <<copy-to,`copy_to`>> feature instead.
2 changes: 2 additions & 0 deletions docs/reference/setup/upgrade.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Elasticsearch can usually be upgraded using a rolling upgrade process, resulting

Before upgrading from 0.90.x or any earlier version to 1.x or later, it is a good idea to consult the <<breaking-changes,breaking changes>> docs.

Before upgrading from 1.x to any more recent version of Elasticsearch, it is a good idea to consult the <<breaking-minor-changes,breaking changes on minor versions>> docs.

[float]
[[backup]]
=== Back Up Your Data!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@ setup:
t2:
type: string
obj:
path: just_name
properties:
t1:
type: string
i_t1:
type: string
index_name: t1
i_t3:
type: string
index_name: t3

- do:
indices.create:
Expand All @@ -35,16 +32,13 @@ setup:
t2:
type: string
obj:
path: just_name
properties:
t1:
type: string
i_t1:
type: string
index_name: t1
i_t3:
type: string
index_name: t3

- do:
cluster.health:
Expand Down Expand Up @@ -75,8 +69,7 @@ setup:
# of a field and thus takes precedence.
- match: {test_index.mappings.test_type.t1.full_name: t1 }
- match: {test_index.mappings.test_type.t2.full_name: t2 }
- match: {test_index.mappings.test_type.t3.full_name: obj.i_t3 }
- length: {test_index.mappings.test_type: 3}
- length: {test_index.mappings.test_type: 2}

---
"Get field mapping with *t1 for fields":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.lucene.search.*;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchIllegalArgumentException;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.lucene.BytesRefs;
Expand Down Expand Up @@ -247,6 +248,10 @@ public Names buildNames(BuilderContext context) {

public String buildIndexName(BuilderContext context) {
String actualIndexName = indexName == null ? name : indexName;
if (context.indexCreatedVersion().onOrAfter(Version.V_1_4_0) && !name.equals(actualIndexName)) {
throw new MapperParsingException("Custom `index_name`s are not supported on indices created on or after "
+ "Elasticsearch 1.4.0. `name` is [" + name + "] while `index_name` is [" + actualIndexName + "]");
}
return context.path().pathAsText(actualIndexName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.index.mapper.object;

import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
import com.google.common.collect.Iterables;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexableField;
Expand All @@ -29,13 +28,12 @@
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ElasticsearchIllegalStateException;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.collect.ImmutableOpenMap;
import org.elasticsearch.common.collect.UpdateInPlaceMap;
import org.elasticsearch.common.joda.FormatDateTimeFormatter;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
Expand Down Expand Up @@ -159,6 +157,10 @@ public T add(Mapper.Builder builder) {

@Override
public Y build(BuilderContext context) {
if (pathType != ContentPath.Type.FULL && context.indexCreatedVersion().onOrAfter(Version.V_1_4_0)) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that we should do
path == ContentPath.Type.JUST_NAME instead of pathType != ContentPath.Type.FULL

In case in the future we want to add a new option...

throw new MapperParsingException("`path: just_name` is not supported on indices created on or after Elasticsearch 1.4.0");
}

ContentPath.Type origPathType = context.path().pathType();
context.path().pathType(pathType);
context.path().add(name);
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/elasticsearch/index/mapper/all/mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"properties":{
"location":{
"type":"string",
"store":"yes",
"index_name":"firstLocation"
"store":"yes"
}
}
},
Expand All @@ -54,4 +53,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"properties":{
"location":{
"type":"string",
"store":"yes",
"index_name":"firstLocation"
"store":"yes"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"properties":{
"location":{
"type":"string",
"store":"yes",
"index_name":"firstLocation"
"store":"yes"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"properties":{
"location":{
"type":"string",
"store":"yes",
"index_name":"firstLocation"
"store":"yes"
}
}
},
Expand All @@ -53,4 +52,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"properties":{
"location":{
"type":"string",
"store":"yes",
"index_name":"firstLocation"
"store":"yes"
}
}
},
Expand All @@ -52,4 +51,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"properties":{
"location":{
"type":"string",
"store":"yes",
"index_name":"firstLocation"
"store":"yes"
}
}
},
Expand All @@ -53,4 +52,4 @@
}
}
}
}
}
Loading