Elasticsearch: Different mapping on staging and prod

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)

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?

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