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

Only use PUT for index creation, not POST. #20001

Merged
merged 2 commits into from
Aug 17, 2016
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
import org.apache.lucene.document.Field;
import org.apache.lucene.document.SortedSetDocValuesField;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.RegexpQuery;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.Version;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
Expand All @@ -40,7 +36,6 @@
import org.elasticsearch.index.fielddata.IndexFieldData;
import org.elasticsearch.index.fielddata.plain.DocValuesIndexFieldData;
import org.elasticsearch.index.fielddata.plain.PagedBytesIndexFieldData;
import org.elasticsearch.index.query.QueryShardContext;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -71,7 +66,8 @@ public class StringFieldMapper extends FieldMapper implements AllFieldMapper.Inc
"type",
// common text parameters, for which the upgrade is straightforward
"index", "store", "doc_values", "omit_norms", "norms", "fields", "copy_to",
"fielddata", "include_in_all", "analyzer", "search_analyzer", "search_quote_analyzer"));
"fielddata", "include_in_all", "analyzer", "search_analyzer", "search_quote_analyzer",
"index_options", "position_increment_gap"));

public static class Defaults {
public static double FIELDDATA_MIN_FREQUENCY = 0;
Expand Down Expand Up @@ -259,7 +255,10 @@ public Mapper.Builder parse(String fieldName, Map<String, Object> node, ParserCo
}

}
throw new IllegalArgumentException("The [string] type is removed in 5.0. You should now use either a [text] "
Set<String> unsupportedParameters = new HashSet<>(node.keySet());
unsupportedParameters.removeAll(autoUpgradeParameters);
throw new IllegalArgumentException("The [string] type is removed in 5.0 and automatic upgrade failed because parameters "
+ unsupportedParameters + " are not supported for automatic upgrades. You should now use either a [text] "
+ "or [keyword] field instead for field [" + fieldName + "]");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class RestCreateIndexAction extends BaseRestHandler {
public RestCreateIndexAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.PUT, "/{index}", this);
controller.registerHandler(RestRequest.Method.POST, "/{index}", this);
}

@SuppressWarnings({"unchecked"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,32 @@ public void testUpgradeNotIndexedString() throws IOException {
assertEquals(IndexOptions.NONE, field.fieldType().indexOptions());
}

public void testUpgradeIndexOptions() throws IOException {
IndexService indexService = createIndex("test");
DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "string")
.field("index_options", "offsets").endObject().endObject()
.endObject().endObject().string();
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
FieldMapper field = mapper.mappers().getMapper("field");
assertThat(field, instanceOf(TextFieldMapper.class));
assertEquals(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, field.fieldType().indexOptions());
}

public void testUpgradePositionGap() throws IOException {
IndexService indexService = createIndex("test");
DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type")
.startObject("properties").startObject("field").field("type", "string")
.field("position_increment_gap", 42).endObject().endObject()
.endObject().endObject().string();
DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping));
FieldMapper field = mapper.mappers().getMapper("field");
assertThat(field, instanceOf(TextFieldMapper.class));
assertEquals(42, field.fieldType().indexAnalyzer().getPositionIncrementGap("field"));
}

public void testIllegalIndexValue() throws IOException {
IndexService indexService = createIndex("test");
DocumentMapperParser parser = indexService.mapperService().documentMapperParser();
Expand Down Expand Up @@ -297,7 +323,11 @@ private void doTestUpgradeRandomMapping(int iter) throws IOException {
}
if (randomBoolean()) {
// this option is not upgraded automatically
mapping.field("index_options", "docs");
if (keyword) {
mapping.field("index_options", "docs");
} else {
mapping.field("ignore_above", 30);
}
shouldUpgrade = false;
}
mapping.endObject().endObject().endObject().endObject();
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/mapper-attachments.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Create a property mapping using the new type `attachment`:

[source,js]
--------------------------
POST /trying-out-mapper-attachments
PUT /trying-out-mapper-attachments
{
"mappings": {
"person": {
Expand Down
56 changes: 28 additions & 28 deletions docs/reference/indices/create-index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ associated with it.

[source,js]
--------------------------------------------------
$ curl -XPUT 'http://localhost:9200/twitter/' -d '{
PUT twitter
{
"settings" : {
"index" : {
"number_of_shards" : 3, <1>
"number_of_replicas" : 2 <2>
}
}
}'
}
--------------------------------------------------
// CONSOLE
Copy link
Member

Choose a reason for hiding this comment

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

❤️

<1> Default for `number_of_shards` is 5
<2> Default for `number_of_replicas` is 1 (ie one replica for each primary shard)

Expand All @@ -33,27 +35,31 @@ index settings can also be defined with http://www.json.org[JSON]:

[source,js]
--------------------------------------------------
$ curl -XPUT 'http://localhost:9200/twitter/' -d '{
PUT twitter
{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}
}'
}
--------------------------------------------------
// CONSOLE

or more simplified

[source,js]
--------------------------------------------------
$ curl -XPUT 'http://localhost:9200/twitter/' -d '{
PUT twitter
{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 2
}
}'
}
--------------------------------------------------
// CONSOLE

[NOTE]
You do not have to explicitly specify `index` section inside the
Expand All @@ -72,7 +78,8 @@ The create index API allows to provide a set of one or more mappings:

[source,js]
--------------------------------------------------
curl -XPOST localhost:9200/test -d '{
PUT test
{
"settings" : {
"number_of_shards" : 1
},
Expand All @@ -83,8 +90,9 @@ curl -XPOST localhost:9200/test -d '{
}
}
}
}'
}
--------------------------------------------------
// CONSOLE

[float]
[[create-index-aliases]]
Expand All @@ -94,7 +102,8 @@ The create index API allows also to provide a set of <<indices-aliases,aliases>>

[source,js]
--------------------------------------------------
curl -XPUT localhost:9200/test -d '{
PUT test
{
"aliases" : {
"alias_1" : {},
"alias_2" : {
Expand All @@ -104,24 +113,9 @@ curl -XPUT localhost:9200/test -d '{
"routing" : "kimchy"
Copy link
Member

Choose a reason for hiding this comment

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

Why nuke this section? Is this no longer override-able by the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, the index creation timestamp cannot be set by users anymore, like the creation version

Copy link
Member

Choose a reason for hiding this comment

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

Perfect! Awesome! I'm glad you converted these docs. Thanks!

}
}
}'
--------------------------------------------------

[float]
=== Creation Date

When an index is created, a timestamp is stored in the index metadata for the creation date. By
default this is automatically generated but it can also be specified using the
`creation_date` parameter on the create index API:

[source,js]
--------------------------------------------------
curl -XPUT localhost:9200/test -d '{
"creation_date" : 1407751337000 <1>
}'
}
--------------------------------------------------

<1> `creation_date` is set using epoch time in milliseconds.
// CONSOLE

[float]
[[create-index-wait-for-active-shards]]
Expand All @@ -138,6 +132,7 @@ what happened:
"shards_acknowledged": true
}
--------------------------------------------------
// TESTRESPONSE

`acknowledged` indicates whether the index was successfully created in the cluster, while
`shards_acknowledged` indices whether the requisite number of shard copies were started for
Expand All @@ -156,19 +151,24 @@ the `wait_for_active_shards` value on all subsequent write operations):

[source,js]
--------------------------------------------------
curl -XPUT localhost:9200/test -d '{
PUT test
{
"settings": {
"index.write.wait_for_active_shards": "2"
}
}
--------------------------------------------------
// CONSOLE
// TEST[skip:requires two nodes]

or through the request parameter `wait_for_active_shards`:

[source,js]
--------------------------------------------------
curl -XPUT localhost:9200/test?wait_for_active_shards=2
PUT test?wait_for_active_shards=2
--------------------------------------------------
// CONSOLE
// TEST[skip:requires two nodes]

A detailed explanation of `wait_for_active_shards` and its possible values can be found
<<index-wait-for-active-shards,here>>.
5 changes: 5 additions & 0 deletions docs/reference/migration/migrate_5_0/rest.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ endpoint should be used in lieu of optimize.
The `GET` HTTP verb for `/_forcemerge` is no longer supported, please use the
`POST` HTTP verb.

==== Index creation endpoint only accepts `PUT`

It used to be possible to create an index by either calling `PUT index_name`
or `POST index_name`. Only the former is now supported.

==== Removed `mem` section from `/_cluster/stats` response

The `mem` section contained only one value, the total memory available
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/search/suggesters/phrase-suggest.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ work. The `reverse` analyzer is used only in the last example.

[source,js]
--------------------------------------------------
POST test
PUT test
{
"settings": {
"index": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"indices.create": {
"documentation": "http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html",
"methods": ["PUT", "POST"],
"methods": ["PUT"],
"url": {
"path": "/{index}",
"paths": ["/{index}"],
Expand Down