# Elasticsearch: Different mapping on staging and prod

**URL:** <https://discuss.elastic.co/t/elasticsearch-different-mapping-on-staging-and-prod/210975>\
**Category:** Elasticsearch\
**Created:** [December 7, 2019, 5:02pm UTC](https://discuss.elastic.co/t/elasticsearch-different-mapping-on-staging-and-prod/210975 "2019-12-07T17:02:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anton1990](https://avatars.discourse-cdn.com/v4/letter/a/e495f1/32.png) [@anton1990](https://discuss.elastic.co/u/anton1990)\
**Post date:** [December 7, 2019, 5:02pm UTC](https://discuss.elastic.co/t/elasticsearch-different-mapping-on-staging-and-prod/210975/1 "2019-12-07T17:02:16Z")

</div>

I have to server environments: 1x staging, 1x productive.  
The following configurations are identical:

- OS version (Ubuntu 18.04.3 LTS)
- elasticsearch version (7.5.0 Build e9ccaed468e2fac2275a3761849cbee64b39519f)
- PHP version (PHP 7.2.24-0ubuntu0.18.04.1 (cli) (built: Oct 28 2019 12:07:07) ( NTS ))
- elasticsearch PHP client v7.4.1 ([https://github.com/elastic/elasticsearch-php](https://github.com/elastic/elasticsearch-php))

The only difference: On Staging MySQL runs on the same server, in the productive environment MySQL runs on an extra server.

I programmed a distance search that uses coordinates to calculate the distance. The data is indexed with the following code:

```
public function createAutoTagsIndex($name)
{
    #$params = ['index' => $name];
    #$response = $this->_client->indices()->delete($params);

    try {
        $params = [
            'index' => $name,
            'body' => [
                'mappings' => [
                    '_source' => [
                        'enabled' => true,
                    ],
                    'properties' => [
                        'pin' => [
                            'properties' => [
                                'location' => [
                                    'type' => 'geo_point',
                                ]
                            ]
                        ],
                    ],
                ],
            ],
        ];

        $response = $this->_client->indices()->create($params);
    } catch (\Exception $ex) {
    }
}

```

and

```
private function getAutoTagDataArray(Tag $tag)
{
    if ($tag->getIsAutoTag() == true && $tag->countUsages() > 0 && is_object($tag->getCategory())) {
        $dataArray = [
            'id' => $tag->getId(),
            'text' => $tag->getText(),
            'slug' => $tag->getSlug(),
            'pin' => [
                'location' => [
                    'lon' => $tag->getPosLon(),
                    'lat' => $tag->getPosLat(),
                ],
            ],
            'relevance' => $tag->getRelevance(),
            'plz' => $tag->getBasePlz(),
            'city' => $tag->getCity(),
            'category_id' => $tag->getCategory()->getId(),
            'has_items' => ($tag->countUsages() > 0),
        ];

        return $dataArray;
    }

    return [];
}

```

and

```
public function indexAutoTags($tags, OutputInterface $output, $config)
{
    $this->initClient($config);
    $indexName = $config['portal_key'] . self::INDEX_TAGS;
    $this->createAutoTagsIndex($indexName);

    $output->writeln("\nStart indexing: <info>Tags</info>");
    $count = 0;
    $size = sizeof((array)$tags);

    /** @var Tag $tag */
    foreach ($tags as $tag) {
        $count++;

        if ($tag->countUsages() > 0) {
            $dataArray = $this->getAutoTagDataArray($tag);

            $params = [
                'index' => $indexName,
                'id' => md5($tag->getId()),
                'body' => $dataArray,
            ];

            $response = $this->_client->index($params);
            $output->writeln('Tag <info>' . $count . '/' . $size . '</info> indexed: ' . $tag->getText());
        }
    }
}

```

## The Problem

Mapping on staging environment:

```
{
  "mhg_autotags" : {
    "mappings" : {
      "properties" : {
        "category_id" : {
          "type" : "long"
        },
        "city" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "has_items" : {
          "type" : "boolean"
        },
        "id" : {
          "type" : "long"
        },
        "pin" : {
          "properties" : {
            "location" : {
              "type" : "geo_point"
            }
          }
        },
        "plz" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "relevance" : {
          "type" : "float"
        },
        "slug" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "text" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

```

Mapping on productive:

```
{
  "mhg_live_autotags" : {
    "mappings" : {
      "properties" : {
        "category_id" : {
          "type" : "long"
        },
        "city" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "has_items" : {
          "type" : "boolean"
        },
        "id" : {
          "type" : "long"
        },
        "pin" : {
          "properties" : {
            "location" : {
              "properties" : {
                "lat" : {
                  "type" : "float"
                },
                "lon" : {
                  "type" : "float"
                }
              }
            }
          }
        },
        "plz" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "relevance" : {
          "type" : "float"
        },
        "slug" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "text" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

```

The mapping for the field "pin" is different on each environment.

The error message from elasticsearch by running a search:

```
`An exception has been thrown during the rendering of a template ("{"error":{"root_cause":[{"type":"parsing_exception","reason":"unknown field [pin.location]","line":1,"col":0}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"mhg_profiles","node":"u47efQ0VRVmUPr461QJPGQ","reason":{"type":"parsing_exception","reason":"unknown field [pin.location]","line":1,"col":0}}]},"status":400}").`

```

What exactly is going wrong here? I have already recreated the index, reinstalled elasticsearch and checked if the source code is identical.

Any Ideas?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 4, 2020, 5:02pm UTC](https://discuss.elastic.co/t/elasticsearch-different-mapping-on-staging-and-prod/210975/2 "2020-01-04T17:02:19Z")

</div>

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