Skip to content

Commit

Permalink
Make sure to use the type _doc in the REST documentation. (elastic#34662
Browse files Browse the repository at this point in the history
)

* Replace custom type names with _doc in REST examples.
* Avoid using two mapping types in the percolator docs.
* Rename doc -> _doc in the main repository README.
* Also replace some custom type names in the HLRC docs.
  • Loading branch information
jtibshirani authored Oct 22, 2018
1 parent d981746 commit f854330
Show file tree
Hide file tree
Showing 47 changed files with 165 additions and 201 deletions.
16 changes: 8 additions & 8 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ h3. Indexing
Let's try and index some twitter like information. First, let's index some tweets (the @twitter@ index will be created automatically):

<pre>
curl -XPUT 'http://localhost:9200/twitter/doc/1?pretty' -H 'Content-Type: application/json' -d '
curl -XPUT 'http://localhost:9200/twitter/_doc/1?pretty' -H 'Content-Type: application/json' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'

curl -XPUT 'http://localhost:9200/twitter/doc/2?pretty' -H 'Content-Type: application/json' -d '
curl -XPUT 'http://localhost:9200/twitter/_doc/2?pretty' -H 'Content-Type: application/json' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
"message": "Another tweet, will it be indexed?"
}'

curl -XPUT 'http://localhost:9200/twitter/doc/3?pretty' -H 'Content-Type: application/json' -d '
curl -XPUT 'http://localhost:9200/twitter/_doc/3?pretty' -H 'Content-Type: application/json' -d '
{
"user": "elastic",
"post_date": "2010-01-15T01:46:38",
Expand All @@ -73,9 +73,9 @@ curl -XPUT 'http://localhost:9200/twitter/doc/3?pretty' -H 'Content-Type: applic
Now, let's see if the information was added by GETting it:

<pre>
curl -XGET 'http://localhost:9200/twitter/doc/1?pretty=true'
curl -XGET 'http://localhost:9200/twitter/doc/2?pretty=true'
curl -XGET 'http://localhost:9200/twitter/doc/3?pretty=true'
curl -XGET 'http://localhost:9200/twitter/_doc/1?pretty=true'
curl -XGET 'http://localhost:9200/twitter/_doc/2?pretty=true'
curl -XGET 'http://localhost:9200/twitter/_doc/3?pretty=true'
</pre>

h3. Searching
Expand Down Expand Up @@ -133,14 +133,14 @@ Elasticsearch supports multiple indices. In the previous example we used an inde
Another way to define our simple twitter system is to have a different index per user (note, though that each index has an overhead). Here is the indexing curl's in this case:

<pre>
curl -XPUT 'http://localhost:9200/kimchy/doc/1?pretty' -H 'Content-Type: application/json' -d '
curl -XPUT 'http://localhost:9200/kimchy/_doc/1?pretty' -H 'Content-Type: application/json' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'

curl -XPUT 'http://localhost:9200/kimchy/doc/2?pretty' -H 'Content-Type: application/json' -d '
curl -XPUT 'http://localhost:9200/kimchy/_doc/2?pretty' -H 'Content-Type: application/json' -d '
{
"user": "kimchy",
"post_date": "2009-11-15T14:12:12",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,9 @@ public void testCreateIndex() throws IOException {

{
// tag::create-index-request-mappings
request.mapping("tweet", // <1>
request.mapping("_doc", // <1>
"{\n" +
" \"tweet\": {\n" +
" \"_doc\": {\n" +
" \"properties\": {\n" +
" \"message\": {\n" +
" \"type\": \"text\"\n" +
Expand All @@ -317,10 +317,10 @@ public void testCreateIndex() throws IOException {
message.put("type", "text");
Map<String, Object> properties = new HashMap<>();
properties.put("message", message);
Map<String, Object> tweet = new HashMap<>();
tweet.put("properties", properties);
jsonMap.put("tweet", tweet);
request.mapping("tweet", jsonMap); // <1>
Map<String, Object> mapping = new HashMap<>();
mapping.put("properties", properties);
jsonMap.put("_doc", mapping);
request.mapping("_doc", jsonMap); // <1>
//end::create-index-mappings-map
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
Expand All @@ -331,7 +331,7 @@ public void testCreateIndex() throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
{
builder.startObject("tweet");
builder.startObject("_doc");
{
builder.startObject("properties");
{
Expand All @@ -346,15 +346,15 @@ public void testCreateIndex() throws IOException {
builder.endObject();
}
builder.endObject();
request.mapping("tweet", builder); // <1>
request.mapping("_doc", builder); // <1>
//end::create-index-mappings-xcontent
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
}
{
request = new CreateIndexRequest("twitter4");
//tag::create-index-mappings-shortcut
request.mapping("tweet", "message", "type=text"); // <1>
request.mapping("_doc", "message", "type=text"); // <1>
//end::create-index-mappings-shortcut
CreateIndexResponse createIndexResponse = client.indices().create(request, RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
Expand Down Expand Up @@ -390,7 +390,7 @@ public void testCreateIndex() throws IOException {
" \"number_of_replicas\" : 0\n" +
" },\n" +
" \"mappings\" : {\n" +
" \"tweet\" : {\n" +
" \"_doc\" : {\n" +
" \"properties\" : {\n" +
" \"message\" : { \"type\" : \"text\" }\n" +
" }\n" +
Expand Down Expand Up @@ -460,7 +460,7 @@ public void testPutMapping() throws IOException {
{
// tag::put-mapping-request
PutMappingRequest request = new PutMappingRequest("twitter"); // <1>
request.type("tweet"); // <2>
request.type("_doc"); // <2>
// end::put-mapping-request

{
Expand Down Expand Up @@ -550,7 +550,7 @@ public void testPutMappingAsync() throws Exception {
}

{
PutMappingRequest request = new PutMappingRequest("twitter").type("tweet");
PutMappingRequest request = new PutMappingRequest("twitter").type("_doc");

// tag::put-mapping-execute-listener
ActionListener<AcknowledgedResponse> listener =
Expand Down Expand Up @@ -586,7 +586,7 @@ public void testGetMapping() throws IOException {
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
PutMappingRequest request = new PutMappingRequest("twitter");
request.type("tweet");
request.type("_doc");
request.source(
"{\n" +
" \"properties\": {\n" +
Expand All @@ -604,7 +604,7 @@ public void testGetMapping() throws IOException {
// tag::get-mapping-request
GetMappingsRequest request = new GetMappingsRequest(); // <1>
request.indices("twitter"); // <2>
request.types("tweet"); // <3>
request.types("_doc"); // <3>
// end::get-mapping-request

// tag::get-mapping-request-masterTimeout
Expand All @@ -622,8 +622,8 @@ public void testGetMapping() throws IOException {

// tag::get-mapping-response
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> allMappings = getMappingResponse.mappings(); // <1>
MappingMetaData typeMapping = allMappings.get("twitter").get("tweet"); // <2>
Map<String, Object> tweetMapping = typeMapping.sourceAsMap(); // <3>
MappingMetaData typeMapping = allMappings.get("twitter").get("_doc"); // <2>
Map<String, Object> mapping = typeMapping.sourceAsMap(); // <3>
// end::get-mapping-response

Map<String, String> type = new HashMap<>();
Expand All @@ -632,7 +632,7 @@ public void testGetMapping() throws IOException {
field.put("message", type);
Map<String, Object> expected = new HashMap<>();
expected.put("properties", field);
assertThat(tweetMapping, equalTo(expected));
assertThat(mapping, equalTo(expected));
}
}

Expand All @@ -643,7 +643,7 @@ public void testGetMappingAsync() throws Exception {
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
PutMappingRequest request = new PutMappingRequest("twitter");
request.type("tweet");
request.type("_doc");
request.source(
"{\n" +
" \"properties\": {\n" +
Expand All @@ -660,7 +660,7 @@ public void testGetMappingAsync() throws Exception {
{
GetMappingsRequest request = new GetMappingsRequest();
request.indices("twitter");
request.types("tweet");
request.types("_doc");

// tag::get-mapping-execute-listener
ActionListener<GetMappingsResponse> listener =
Expand All @@ -682,16 +682,16 @@ public void onFailure(Exception e) {
final ActionListener<GetMappingsResponse> latchListener = new LatchedActionListener<>(listener, latch);
listener = ActionListener.wrap(r -> {
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> allMappings = r.mappings();
MappingMetaData typeMapping = allMappings.get("twitter").get("tweet");
Map<String, Object> tweetMapping = typeMapping.sourceAsMap();
MappingMetaData typeMapping = allMappings.get("twitter").get("_doc");
Map<String, Object> mapping = typeMapping.sourceAsMap();

Map<String, String> type = new HashMap<>();
type.put("type", "text");
Map<String, Object> field = new HashMap<>();
field.put("message", type);
Map<String, Object> expected = new HashMap<>();
expected.put("properties", field);
assertThat(tweetMapping, equalTo(expected));
assertThat(mapping, equalTo(expected));
latchListener.onResponse(r);
}, e -> {
latchListener.onFailure(e);
Expand All @@ -714,7 +714,7 @@ public void testGetFieldMapping() throws IOException, InterruptedException {
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
PutMappingRequest request = new PutMappingRequest("twitter");
request.type("tweet");
request.type("_doc");
request.source(
"{\n" +
" \"properties\": {\n" +
Expand All @@ -734,7 +734,7 @@ public void testGetFieldMapping() throws IOException, InterruptedException {
// tag::get-field-mapping-request
GetFieldMappingsRequest request = new GetFieldMappingsRequest(); // <1>
request.indices("twitter"); // <2>
request.types("tweet"); // <3>
request.types("_doc"); // <3>
request.fields("message", "timestamp"); // <4>
// end::get-field-mapping-request

Expand All @@ -757,7 +757,7 @@ public void testGetFieldMapping() throws IOException, InterruptedException {
final Map<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>>> mappings =
response.mappings();// <1>
final Map<String, GetFieldMappingsResponse.FieldMappingMetaData> typeMappings =
mappings.get("twitter").get("tweet"); // <2>
mappings.get("twitter").get("_doc"); // <2>
final GetFieldMappingsResponse.FieldMappingMetaData metaData =
typeMappings.get("message");// <3>

Expand Down Expand Up @@ -789,7 +789,7 @@ public void onFailure(Exception e) {
final Map<String, Map<String, Map<String, GetFieldMappingsResponse.FieldMappingMetaData>>> mappings =
r.mappings();
final Map<String, GetFieldMappingsResponse.FieldMappingMetaData> typeMappings =
mappings.get("twitter").get("tweet");
mappings.get("twitter").get("_doc");
final GetFieldMappingsResponse.FieldMappingMetaData metaData1 = typeMappings.get("message");

final String fullName = metaData1.fullName();
Expand Down Expand Up @@ -2114,9 +2114,9 @@ public void testPutTemplate() throws Exception {

{
// tag::put-template-request-mappings-json
request.mapping("tweet", // <1>
request.mapping("_doc", // <1>
"{\n" +
" \"tweet\": {\n" +
" \"_doc\": {\n" +
" \"properties\": {\n" +
" \"message\": {\n" +
" \"type\": \"text\"\n" +
Expand All @@ -2135,10 +2135,10 @@ public void testPutTemplate() throws Exception {
message.put("type", "text");
Map<String, Object> properties = new HashMap<>();
properties.put("message", message);
Map<String, Object> tweet = new HashMap<>();
tweet.put("properties", properties);
jsonMap.put("tweet", tweet);
request.mapping("tweet", jsonMap); // <1>
Map<String, Object> mapping = new HashMap<>();
mapping.put("properties", properties);
jsonMap.put("_doc", mapping);
request.mapping("_doc", jsonMap); // <1>
//end::put-template-request-mappings-map
assertTrue(client.indices().putTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
}
Expand All @@ -2147,7 +2147,7 @@ public void testPutTemplate() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
{
builder.startObject("tweet");
builder.startObject("_doc");
{
builder.startObject("properties");
{
Expand All @@ -2162,13 +2162,13 @@ public void testPutTemplate() throws Exception {
builder.endObject();
}
builder.endObject();
request.mapping("tweet", builder); // <1>
request.mapping("_doc", builder); // <1>
//end::put-template-request-mappings-xcontent
assertTrue(client.indices().putTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
}
{
//tag::put-template-request-mappings-shortcut
request.mapping("tweet", "message", "type=text"); // <1>
request.mapping("_doc", "message", "type=text"); // <1>
//end::put-template-request-mappings-shortcut
assertTrue(client.indices().putTemplate(request, RequestOptions.DEFAULT).isAcknowledged());
}
Expand Down Expand Up @@ -2197,7 +2197,7 @@ public void testPutTemplate() throws Exception {
" \"number_of_shards\": 1\n" +
" },\n" +
" \"mappings\": {\n" +
" \"tweet\": {\n" +
" \"_doc\": {\n" +
" \"properties\": {\n" +
" \"message\": {\n" +
" \"type\": \"text\"\n" +
Expand Down Expand Up @@ -2264,9 +2264,9 @@ public void testGetTemplates() throws Exception {
PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest("my-template");
putRequest.patterns(Arrays.asList("pattern-1", "log-*"));
putRequest.settings(Settings.builder().put("index.number_of_shards", 3).put("index.number_of_replicas", 1));
putRequest.mapping("tweet",
putRequest.mapping("_doc",
"{\n" +
" \"tweet\": {\n" +
" \"_doc\": {\n" +
" \"properties\": {\n" +
" \"message\": {\n" +
" \"type\": \"text\"\n" +
Expand Down
6 changes: 3 additions & 3 deletions docs/groovy-api/anatomy.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ success and failures, as well as blocking for the response. For example:
--------------------------------------------------
def indexR = client.index {
index "test"
type "type1"
type "_doc"
id "1"
source {
test = "value"
Expand Down Expand Up @@ -69,7 +69,7 @@ parameter option (the `GActionFuture` handling). For example:
--------------------------------------------------
def indexR = client.index (new IndexRequest(
index: "test",
type: "type1",
type: "_doc",
id: "1",
source: {
test = "value"
Expand All @@ -92,7 +92,7 @@ with the added `gexecute` which returns the `GActionFuture`:

[source,groovy]
--------------------------------------------------
def indexR = node.client.prepareIndex("test", "type1", "1").setSource({
def indexR = node.client.prepareIndex("test", "_doc", "1").setSource({
test = "value"
complex {
value1 = "value1"
Expand Down
2 changes: 1 addition & 1 deletion docs/groovy-api/delete.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ example:
--------------------------------------------------
def deleteF = node.client.delete {
index "test"
type "type1"
type "_doc"
id "1"
}
--------------------------------------------------
2 changes: 1 addition & 1 deletion docs/groovy-api/get.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ converted to a `Map` which means using Groovy to navigate it is simple:
--------------------------------------------------
def getF = node.client.get {
index "test"
type "type1"
type "_doc"
id "1"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/groovy-api/index_.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ closure. For example:
--------------------------------------------------
def indexR = client.index {
index "test"
type "type1"
type "_doc"
id "1"
source {
test = "value"
Expand Down
Loading

0 comments on commit f854330

Please sign in to comment.