_source excludes not working

This is related to my previous post

I would simply like to be able to exclude fields from being included in my index.

Here is my first approach which does not work. It follows this page from the manual: _source field | Elasticsearch Guide [7.15] | Elastic
I know that this only excludes the field from the _source, and not from being indexed, but still I would like to know how to use it.
I am using Elasticsearch 2.1

Here comes my code example:

curl -XPOST 'http://192.168.56.102:9200/test' -d '{"mappings":{"my_type":{"_source":{"excludes":["ignoreme"]}}}}'

curl -XGET http://192.168.56.102:9200/test?pretty
{
  "test" : {
    "aliases" : { },
    "mappings" : {
      "my_type" : {
        "_source" : {
          "excludes" : [ "ignoreme" ]
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1452157634005",
        "uuid" : "QBa6kp71SQm-AZOfORzy-w",
        "number_of_replicas" : "1",
        "number_of_shards" : "5",
        "version" : {
          "created" : "2010099"
        }
      }
    },
    "warmers" : { }
  }
}

curl -XPOST 'http://192.168.56.102:9200/test/documents/1' -d '{"title":"Something","ignoreme":"I should not be here"}'

curl -XGET http://192.168.56.102:9200/test/documents/1
{
  "_index" : "test",
  "_type" : "documents",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "_source":{"title":"Something","ignoreme":"I should not be here"}
}

Why does "ignoreme" show up in the _source of the GET call?

The problem is that you configured a mapping for the "my_type" type but then you post documents into "documents".

1 Like

Thanks! I messed that up when writing the example for this question.
Now it works, so I can try again on my original data. Thanks again!