DEV Community

Mallikarjun H T
Mallikarjun H T

Posted on

ES Index API - part 3

PUT Mappings

create index with mappings

curl -X PUT "localhost:9200/twitter?pretty" -H 'Content-Type: application/json' -d'
{}'

curl -X PUT "localhost:9200/twitter/_mapping/_doc?pretty" -H 'Content-Type: application/json' -d'
{
  "properties": {
    "email": {
      "type": "keyword"
    }
  }
}'

Enter fullscreen mode Exit fullscreen mode

update existing index

curl -X PUT "localhost:9200/my_index?pretty" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "_doc": {
      "properties": {
        "name": {
          "properties": {
            "first": {
              "type": "text"
            }
          }
        },
        "user_id": {
          "type": "keyword"
        }
      }
    }
  }
}'

curl -X PUT "localhost:9200/my_index/_mapping/_doc?pretty" -H 'Content-Type: application/json' -d'
{
  "properties": {
    "name": {
      "properties": {
        "last": { 
          "type": "text"
        }
      }
    },
    "user_id": {
      "type": "keyword",
      "ignore_above": 100 
    }
  }
}'
Enter fullscreen mode Exit fullscreen mode

Get Mappings

curl -X GET "localhost:9200/twitter/_mapping/_doc?pretty"
Enter fullscreen mode Exit fullscreen mode

GET field mapping

curl -X GET "localhost:9200/publications/_mapping/_doc/field/title?pretty"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)