0

I have inherited a legacy code which is using Elastic Search API to create indices and index content.

The mapping JSON was created for v1.5 and looks as follows:

{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    },
    "mappings": {
      "users": {
        "properties": {
          "created_at": {
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss"
          },
          "id": {
            "type": "double"
          },
          "name": {
            "type": "string"
          },
          "org_id": {
            "type": "double"
          },
          "type_priority": {
            "type": "double"
          }
        }
      },
      "comment_idea": {
        "properties": {
          "author_id": {
            "type": "double"
          },
          "comment": {
            "type": "string"
          },
          "created_at": {
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss"
          },
          "id": {
            "type": "double"
          },
          "idea_id": {
            "type": "double"
          },
          "org_id": {
            "type": "double"
          }
        }
      },
  }
}

Of course, there are a lot more types such as users, comment_idea as shown in the example above.

As I'm not familiar that well with Elastic Search, my question is how to transform this mapping JSON for 7.1?

As I understand 7.1 has removed types and this mapping JSON is considered invalid - I do not get an error but the mapping is not accepted (created).

rock3t
  • 2,193
  • 2
  • 19
  • 24

1 Answers1

1

You need to split that multi-type index into several indexes as you cannot store more than one mapping type in a single index. In addition you need to change string to text.

So you need to create several indexes, like this:

PUT users
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "created_at": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
      },
      "id": {
        "type": "double"
      },
      "name": {
        "type": "text"
      },
      "org_id": {
        "type": "double"
      },
      "type_priority": {
        "type": "double"
      }
    }
  }
}

PUT comment_idea
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "author_id": {
        "type": "double"
      },
      "comment": {
        "type": "text"
      },
      "created_at": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss"
      },
      "id": {
        "type": "double"
      },
      "idea_id": {
        "type": "double"
      },
      "org_id": {
        "type": "double"
      }
    }
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • That was my understanding too, great to get a confirmation! – rock3t Nov 29 '19 at 14:32
  • I did not put "_timestamp": {"enabled": true} in my question but that was another breaking change. What would be the best approach to get that back in the index? – rock3t Nov 29 '19 at 14:36
  • `_timestamp` has been deprecated a long time ago. You should simply add a field that represents the timestamp of when the document is indexed. – Val Nov 29 '19 at 14:37
  • All good Val. Got structure re-created and update code to index. Now working on changing the search query. It's all based on query.filtered which is deprecated as well. I'll post a question in a few minutes for this as well. – rock3t Dec 02 '19 at 11:33
  • You don't need to, check this one: https://stackoverflow.com/questions/40519806/no-query-registered-for-filtered/40521602#40521602 – Val Dec 02 '19 at 11:43