Skip to content

Commit

Permalink
Adds to mappings API (#1766)
Browse files Browse the repository at this point in the history
Signed-off-by: Fanit Kolchina <[email protected]>

Signed-off-by: Fanit Kolchina <[email protected]>
  • Loading branch information
kolchfa-aws authored Nov 1, 2022
1 parent 887ed47 commit ebd97d0
Showing 1 changed file with 77 additions and 2 deletions.
79 changes: 77 additions & 2 deletions _opensearch/mappings.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Mapping
nav_order: 13
---

# About Mappings
# Mapping

You can define how documents and their fields are stored and indexed by creating a mapping.

Expand Down Expand Up @@ -45,6 +45,7 @@ numeric detection string | If disabled, OpenSearch may automatically process num
If you know exactly what your field data types need to be, you can specify them in your request body when creating your index.

```json
PUT sample-index1
{
"mappings": {
"properties": {
Expand All @@ -65,6 +66,22 @@ If you know exactly what your field data types need to be, you can specify them
}
```

To add mappings to an existing index or data stream, you can send a request to the `_mapping` endpoint using the `PUT` or `POST` HTTP method:

```json
POST sample-index1/_mapping
{
"properties": {
"year": { "type" : "text" },
"age": { "type" : "integer" },
"director":{ "type" : "text" }
}
}
```

You cannot change the mapping of an existing field, you can only modify the field's mapping parameters.
{: .note}

---
## Mapping example usage

Expand Down Expand Up @@ -102,4 +119,62 @@ PUT _index_ip/_doc/<id>
}
```

This indexed ip_range does not throw an error because `ignore_malformed` is set to true.
This indexed ip_range does not throw an error because `ignore_malformed` is set to true.

## Get a mapping

To get all mappings for one or more indexes, use the following request:

```json
GET <index>/_mapping
```

In the above request, `<index>` may be an index name or a comma-separated list of index names.

To get all mappings for all indexes, use the following request:

```json
GET _mapping
```

To get a mapping for a specific field, provide the index name and the field name:

```json
GET _mapping/field/<fields>
GET /<index>/_mapping/field/<fields>
```

Both `<index>` and `<fields>` can be specified as one value or a comma-separated list.

For example, the following request retrieves the mapping for the `year` and `age` fields in `sample-index1`:

```json
GET sample-index1/_mapping/field/year,age
```

The response contains the specified fields:

```json
{
"sample-index1" : {
"mappings" : {
"year" : {
"full_name" : "year",
"mapping" : {
"year" : {
"type" : "text"
}
}
},
"age" : {
"full_name" : "age",
"mapping" : {
"age" : {
"type" : "integer"
}
}
}
}
}
}
```

0 comments on commit ebd97d0

Please sign in to comment.