la-haute-societe / craft-elasticsearch

Bring the power of Elasticsearch to your Craft CMS projects
Other
18 stars 14 forks source link

Creating Index on ES 6 fails #17

Closed floatingbits closed 2 years ago

floatingbits commented 3 years ago

I need to use ES at Version 6. When I tried to refresh my ES Index in the Craft Cp, I got lots of errors looking like this:

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Root mapping definition has unsupported parameters:  [year : {type=date}]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [properties]: Root mapping definition has unsupported parameters:  [year : {type=date}]",
    "caused_by" : {
      "type" : "mapper_parsing_exception",
      "reason" : "Root mapping definition has unsupported parameters:  [year : {type=date}]"
    }
  },
  "status" : 400
}

It is kind of the opposite issue as in this comment, where someone shows the effect of ES6 Version request body on an ES7 Version server: https://stackoverflow.com/a/66982849/7439920

I'm pretty sure it is due to a difference in ES 6 vs ES 7 dsl and can be fixed, in my case by adding $schema['mappings'] = [static::index() => $schema['mappings'] ]; before $command->createIndex(static::index(), $schema); to ElasticsearchRecord::createIndex($index, $configuration), of course adding an appropriate if-condition and an according configuration for ES7 vs ES6.

My setup: ES 6.8.20, Craft 3.7.7, Craft Elastic Search 1.4.0