How to use custom field type in mappings to achieve multiple type mappings within an index?

Hi, I'm trying to migrate my elasticsearch from 2.4 to 7.5

I was working on fixing breaking changes in the mappings. This example here (for custom field type): https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html seems to be not working as it gives error for the doc field.

Here they ES blog has mentioned best use of custom type field: https://www.elastic.co/blog/kibana-6-removal-of-mapping-types

But I'm not able to figure it out, how should I create it ?

Based on this question - consider there are two types of mapping like product and category. I want them within 1 index only. How should I create it ?

Reference doubt on discussion forum: How to avoid duplicate fields copied during bulk indexing?

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

So provide a typical example of your 2 types.

@dadoonet I'm using GoLang client API. This one- GitHub - olivere/elastic: Deprecated: Use the official Elasticsearch client for Go at https://github.com/elastic/go-elasticsearch

My mapping for single index including multiple types: product and category.

mappings := map[string]interface{}{
		"properties": map[string]interface{}{
			"category": map[string]interface{}{
				"properties": map[string]interface{}{
					"id":   map[string]interface{}{"type": "long"},
					"name": map[string]interface{}{"type": "text"},
					"type": map[string]interface{}{"type": "text"},
					"image_version": map[string]interface{}{
						"type": "nested",
						"properties": map[string]interface{}{
							"image_height": map[string]interface{}{"type": "float"},
							"image_width":  map[string]interface{}{"type": "float"},
						},
					},
				},
			},
			"product": map[string]interface{}{
				"properties": map[string]interface{}{
					"activity_name": map[string]interface{}{"type": "text"},
					"app_type":      map[string]interface{}{"type": "text"},
				},
			},
		},
	}

When I try to bulk index the data, it creates a single index with mappings like this:

{
  "mappings": {
    "properties": { 
      "category": {
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "keyword"
          },
          "type": {
            "type": "text"
          },
          "image_version": {
            "type": "nested",
            "properties": {
              "image_height": {
                "type": "float"
              },
              "image_width": {
                "type": "float"
              }
            }
          }
        }
      },
      "id": {
        "type": "integer"
      },
      "name": {
        "type": "keyword"
      },
      "type": {
        "type": "text"
      },
      "image_version": {
        "type": "nested",
        "properties": {
          "image_height": {
            "type": "float"
          },
          "image_width": {
            "type": "float"
          }
        }
      },
      "product": {
        "properties": {
          "activity_name": {
            "type": "text"
          },
          "app_type": {
            "type": "text"
          }
        }
      }
    }
  }
}

As you can notice it is copying category fields data outside category root field too.

Why the fields inside properties are being copied outside category ? How should I avoid it? How should I define custom types?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.