Luis Muñiz
Luis Muñiz

Reputation: 4811

How can I obtain the detailed mappings of a type?

I created a type with these mappings:

{
       "test" : {
                "_all" : {"enabled" : false},
                "_source" : {"enabled" : true},
                "properties": {
                    "a" : {"type" : "string","index" : "not_analyzed", "store": false },
                    "b" : {"type" : "double", "store": false },
                    "c" : {"type" : "date", "store": false }            
                }
       }
}

But when I try to retrieve the mappings I get this response from elasticsearch:

{
  "my-index": {
     "mappings": {
        "test": {
           "_all": {
              "enabled": false
           },
           "properties": {
              "a": {
                 "type": "string",
                 "index": "not_analyzed"
              },
              "b": {
                 "type": "double"
              },
              "c": {
                 "type": "date",
                 "format": "dateOptionalTime"
              }
           }
        }
     }
  }
}

Why has the store attribute dissappeared? Did I make a mistake in my PUT mapping?

Upvotes: 0

Views: 60

Answers (1)

Olly Cruickshank
Olly Cruickshank

Reputation: 6190

When getting an Elasticsearch mapping it doesn't show the settings that have the default values.

The default is not to store individual fields (only the source document is stored) - test this by adding a field with store enabled:

curl -XPUT "http://localhost:9200/myindex/test/_mapping" -d'
{
   "test" : {
            "_all" : {"enabled" : false},
            "_source" : {"enabled" : true},
            "properties": {
                "a" : {"type" : "string","index" : "not_analyzed", "store": false },
                "b" : {"type" : "double", "store": false },
                "c" : {"type" : "date", "store": false },
                "d" : {"type" : "string", "store": true }
             }
 }'

getting the mapping shows that field d is stored.

curl -XGET "http://localhost:9200/myindex/test/_mapping?pretty"
{
  "myindex" : {
    "mappings" : {
      "test" : {
        "_all" : {
          "enabled" : false
        },
        "properties" : {
          "a" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "b" : {
            "type" : "double"
          },
          "c" : {
            "type" : "date",
            "format" : "dateOptionalTime"
          },
          "d" : {
            "type" : "string",
            "store" : true
          }
        }
      }
    }
  }
}

Upvotes: 2

Related Questions