Skip to content

Commit 8519ca2

Browse files
committed
Remove CreateIndexRequest#mapping(Object... source), as it's not as useful for the HLRC.
1 parent 6892e0f commit 8519ca2

File tree

7 files changed

+124
-37
lines changed

7 files changed

+124
-37
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/indices/CreateIndexRequest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,6 @@ public CreateIndexRequest mapping(Map<String, ?> source) {
200200
throw new ElasticsearchGenerationException("Failed to generate [" + source + "]", e);
201201
}
202202
}
203-
204-
/**
205-
* A specialized simplified mapping source method, takes the form of simple properties definition:
206-
* ("field1", "type=string,store=true").
207-
*/
208-
public CreateIndexRequest mapping(Object... source) {
209-
mapping(PutMappingRequest.buildFromSimplifiedDef(null, source));
210-
return this;
211-
}
212203

213204
/**
214205
* Sets the aliases that will be associated with the index when it gets created

client/rest-high-level/src/test/java/org/elasticsearch/client/MachineLearningIT.java

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
import org.elasticsearch.client.ml.job.stats.JobStats;
114114
import org.elasticsearch.client.ml.job.util.PageParams;
115115
import org.elasticsearch.common.unit.TimeValue;
116+
import org.elasticsearch.common.xcontent.XContentFactory;
116117
import org.elasticsearch.common.xcontent.XContentType;
117118
import org.elasticsearch.rest.RestStatus;
118119
import org.elasticsearch.search.SearchHit;
@@ -527,7 +528,16 @@ public void testStartDatafeed() throws Exception {
527528

528529
// Set up the index and docs
529530
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
530-
createIndexRequest.mapping("timestamp", "type=date", "total", "type=long");
531+
createIndexRequest.mapping(XContentFactory.jsonBuilder().startObject()
532+
.startObject("properties")
533+
.startObject("timestamp")
534+
.field("type", "date")
535+
.endObject()
536+
.startObject("total")
537+
.field("type", "long")
538+
.endObject()
539+
.endObject()
540+
.endObject());
531541
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
532542
BulkRequest bulk = new BulkRequest();
533543
bulk.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
@@ -601,7 +611,16 @@ public void testStopDatafeed() throws Exception {
601611

602612
// Set up the index
603613
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
604-
createIndexRequest.mapping("timestamp", "type=date", "total", "type=long");
614+
createIndexRequest.mapping(XContentFactory.jsonBuilder().startObject()
615+
.startObject("properties")
616+
.startObject("timestamp")
617+
.field("type", "date")
618+
.endObject()
619+
.startObject("total")
620+
.field("type", "long")
621+
.endObject()
622+
.endObject()
623+
.endObject());
605624
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
606625

607626
// create the job and the datafeed
@@ -665,7 +684,16 @@ public void testGetDatafeedStats() throws Exception {
665684

666685
// Set up the index
667686
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
668-
createIndexRequest.mapping("timestamp", "type=date", "total", "type=long");
687+
createIndexRequest.mapping(XContentFactory.jsonBuilder().startObject()
688+
.startObject("properties")
689+
.startObject("timestamp")
690+
.field("type", "date")
691+
.endObject()
692+
.startObject("total")
693+
.field("type", "long")
694+
.endObject()
695+
.endObject()
696+
.endObject());
669697
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
670698

671699
// create the job and the datafeed
@@ -734,7 +762,16 @@ public void testPreviewDatafeed() throws Exception {
734762

735763
// Set up the index and docs
736764
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
737-
createIndexRequest.mapping("timestamp", "type=date", "total", "type=long");
765+
createIndexRequest.mapping(XContentFactory.jsonBuilder().startObject()
766+
.startObject("properties")
767+
.startObject("timestamp")
768+
.field("type", "date")
769+
.endObject()
770+
.startObject("total")
771+
.field("type", "long")
772+
.endObject()
773+
.endObject()
774+
.endObject());
738775
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
739776
BulkRequest bulk = new BulkRequest();
740777
bulk.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
@@ -791,7 +828,17 @@ private String createExpiredData(String jobId) throws Exception {
791828
String indexId = jobId + "-data";
792829
// Set up the index and docs
793830
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexId);
794-
createIndexRequest.mapping("timestamp", "type=date,format=epoch_millis", "total", "type=long");
831+
createIndexRequest.mapping(XContentFactory.jsonBuilder().startObject()
832+
.startObject("properties")
833+
.startObject("timestamp")
834+
.field("type", "date")
835+
.field("format", "epoch_millis")
836+
.endObject()
837+
.startObject("total")
838+
.field("type", "long")
839+
.endObject()
840+
.endObject()
841+
.endObject());
795842
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
796843
BulkRequest bulk = new BulkRequest();
797844
bulk.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,14 @@ public void afterBulk(long executionId, BulkRequest request,
15471547
// Not entirely sure if _termvectors belongs to CRUD, and in the absence of a better place, will have it here
15481548
public void testTermVectors() throws Exception {
15491549
RestHighLevelClient client = highLevelClient();
1550-
CreateIndexRequest authorsRequest = new CreateIndexRequest("authors").mapping("user", "type=keyword");
1550+
CreateIndexRequest authorsRequest = new CreateIndexRequest("authors")
1551+
.mapping(XContentFactory.jsonBuilder().startObject()
1552+
.startObject("properties")
1553+
.startObject("user")
1554+
.field("type", "keyword")
1555+
.endObject()
1556+
.endObject()
1557+
.endObject());
15511558
CreateIndexResponse authorsResponse = client.indices().create(authorsRequest, RequestOptions.DEFAULT);
15521559
assertTrue(authorsResponse.isAcknowledged());
15531560
client.index(new IndexRequest("index").id("1").source("user", "kimchy"), RequestOptions.DEFAULT);
@@ -1671,7 +1678,14 @@ public void onFailure(Exception e) {
16711678
// Not entirely sure if _mtermvectors belongs to CRUD, and in the absence of a better place, will have it here
16721679
public void testMultiTermVectors() throws Exception {
16731680
RestHighLevelClient client = highLevelClient();
1674-
CreateIndexRequest authorsRequest = new CreateIndexRequest("authors").mapping("user", "type=text");
1681+
CreateIndexRequest authorsRequest = new CreateIndexRequest("authors")
1682+
.mapping(XContentFactory.jsonBuilder().startObject()
1683+
.startObject("properties")
1684+
.startObject("user")
1685+
.field("type", "keyword")
1686+
.endObject()
1687+
.endObject()
1688+
.endObject());
16751689
CreateIndexResponse authorsResponse = client.indices().create(authorsRequest, RequestOptions.DEFAULT);
16761690
assertTrue(authorsResponse.isAcknowledged());
16771691
client.index(new IndexRequest("index").id("1").source("user", "kimchy"), RequestOptions.DEFAULT);

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,6 @@ public void testCreateIndex() throws IOException {
355355
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
356356
assertTrue(createIndexResponse.isAcknowledged());
357357
}
358-
{
359-
request = new CreateIndexRequest("twitter4");
360-
//tag::create-index-mappings-shortcut
361-
request.mapping("message", "type=text"); // <1>
362-
//end::create-index-mappings-shortcut
363-
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
364-
assertTrue(createIndexResponse.isAcknowledged());
365-
}
366358

367359
request = new CreateIndexRequest("twitter5");
368360
// tag::create-index-request-aliases

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/MlClientDocumentationIT.java

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
import org.elasticsearch.client.ml.job.util.PageParams;
140140
import org.elasticsearch.common.bytes.BytesReference;
141141
import org.elasticsearch.common.unit.TimeValue;
142+
import org.elasticsearch.common.xcontent.XContentFactory;
142143
import org.elasticsearch.common.xcontent.XContentType;
143144
import org.elasticsearch.index.query.QueryBuilders;
144145
import org.elasticsearch.search.aggregations.AggregatorFactories;
@@ -869,7 +870,16 @@ public void testPreviewDatafeed() throws Exception {
869870
String datafeedId = job.getId() + "-feed";
870871
String indexName = "preview_data_2";
871872
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
872-
createIndexRequest.mapping("timestamp", "type=date", "total", "type=long");
873+
createIndexRequest.mapping(XContentFactory.jsonBuilder().startObject()
874+
.startObject("properties")
875+
.startObject("timestamp")
876+
.field("type", "date")
877+
.endObject()
878+
.startObject("total")
879+
.field("type", "long")
880+
.endObject()
881+
.endObject()
882+
.endObject());
873883
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
874884
DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, job.getId())
875885
.setIndices(indexName)
@@ -928,7 +938,16 @@ public void testStartDatafeed() throws Exception {
928938
String datafeedId = job.getId() + "-feed";
929939
String indexName = "start_data_2";
930940
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
931-
createIndexRequest.mapping("timestamp", "type=date", "total", "type=long");
941+
createIndexRequest.mapping(XContentFactory.jsonBuilder().startObject()
942+
.startObject("properties")
943+
.startObject("timestamp")
944+
.field("type", "date")
945+
.endObject()
946+
.startObject("total")
947+
.field("type", "long")
948+
.endObject()
949+
.endObject()
950+
.endObject());
932951
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
933952
DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId, job.getId())
934953
.setIndices(indexName)
@@ -1048,7 +1067,16 @@ public void testGetDatafeedStats() throws Exception {
10481067
String datafeedId1 = job.getId() + "-feed";
10491068
String indexName = "datafeed_stats_data_2";
10501069
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
1051-
createIndexRequest.mapping("timestamp", "type=date", "total", "type=long");
1070+
createIndexRequest.mapping(XContentFactory.jsonBuilder().startObject()
1071+
.startObject("properties")
1072+
.startObject("timestamp")
1073+
.field("type", "date")
1074+
.endObject()
1075+
.startObject("total")
1076+
.field("type", "long")
1077+
.endObject()
1078+
.endObject()
1079+
.endObject());
10521080
highLevelClient().indices().create(createIndexRequest, RequestOptions.DEFAULT);
10531081
DatafeedConfig datafeed = DatafeedConfig.builder(datafeedId1, job.getId())
10541082
.setIndices(indexName)

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.elasticsearch.common.text.Text;
5858
import org.elasticsearch.common.unit.Fuzziness;
5959
import org.elasticsearch.common.unit.TimeValue;
60+
import org.elasticsearch.common.xcontent.XContentFactory;
6061
import org.elasticsearch.common.xcontent.XContentType;
6162
import org.elasticsearch.index.get.GetResult;
6263
import org.elasticsearch.index.query.MatchQueryBuilder;
@@ -1249,12 +1250,26 @@ public void onFailure(Exception e) {
12491250

12501251
private void indexSearchTestData() throws IOException {
12511252
CreateIndexRequest authorsRequest = new CreateIndexRequest("authors")
1252-
.mapping("user", "type=keyword,doc_values=false");
1253+
.mapping(XContentFactory.jsonBuilder().startObject()
1254+
.startObject("properties")
1255+
.startObject("user")
1256+
.field("type", "keyword")
1257+
.field("doc_values", "false")
1258+
.endObject()
1259+
.endObject()
1260+
.endObject());
12531261
CreateIndexResponse authorsResponse = highLevelClient().indices().create(authorsRequest, RequestOptions.DEFAULT);
12541262
assertTrue(authorsResponse.isAcknowledged());
12551263

12561264
CreateIndexRequest reviewersRequest = new CreateIndexRequest("contributors")
1257-
.mapping("user", "type=keyword,store=true");
1265+
.mapping(XContentFactory.jsonBuilder().startObject()
1266+
.startObject("properties")
1267+
.startObject("user")
1268+
.field("type", "keyword")
1269+
.field("store", "true")
1270+
.endObject()
1271+
.endObject()
1272+
.endObject());
12581273
CreateIndexResponse reviewersResponse = highLevelClient().indices().create(reviewersRequest, RequestOptions.DEFAULT);
12591274
assertTrue(reviewersResponse.isAcknowledged());
12601275

@@ -1368,7 +1383,14 @@ public void onFailure(Exception e) {
13681383

13691384
private static void indexCountTestData() throws IOException {
13701385
CreateIndexRequest authorsRequest = new CreateIndexRequest("author")
1371-
.mapping("user", "type=keyword,doc_values=false");
1386+
.mapping(XContentFactory.jsonBuilder().startObject()
1387+
.startObject("properties")
1388+
.startObject("user")
1389+
.field("type", "keyword")
1390+
.field("doc_values", "false")
1391+
.endObject()
1392+
.endObject()
1393+
.endObject());
13721394
CreateIndexResponse authorsResponse = highLevelClient().indices().create(authorsRequest, RequestOptions.DEFAULT);
13731395
assertTrue(authorsResponse.isAcknowledged());
13741396

docs/java-rest/high-level/indices/create_index.asciidoc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ include-tagged::{doc-tests-file}[{api}-mappings-xcontent]
5555
<1> Mapping source provided as an `XContentBuilder` object, the Elasticsearch
5656
built-in helpers to generate JSON content
5757

58-
["source","java",subs="attributes,callouts,macros"]
59-
--------------------------------------------------
60-
include-tagged::{doc-tests-file}[{api}-mappings-shortcut]
61-
--------------------------------------------------
62-
<1> Mapping source provided as `Object` key-pairs, which gets converted to
63-
JSON format
64-
6558
==== Index aliases
6659
Aliases can be set at index creation time
6760

0 commit comments

Comments
 (0)