App Search: Update schema mapping

I have a date field which in two of my indexes are incorrectly being mapped as a text field. How can I change this so it is recognized as a date?
I've tried the following, but this didn't work, possibly because the mapping is dynamic:

PUT /<index>/_mapping {
  "properties": {
    "date": {
      "type": "date"
    }
  }
}
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "mapper [date] cannot be changed from type [text] to [date]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "mapper [date] cannot be changed from type [text] to [date]"
  },
  "status": 400
}

You can't change the type on an existing index. You need to reindex your data using the right type from the start. I mean in Elasticsearch.

If you are using App Search, you can do that from the UI I think.

I am using App Search, and did think about re-indexing all data, and in fact did trigger the crawler to re-index all documents, but the type of the field did not change, and I didn't find an option to delete all documents.

For Elasticsearch-backed engines: If the mapping already exists as text, even deleting documents and re-crawling won't change the mapping. You'll need to create a brand new index with the correct mapping and reindex.

For App Search managed engines: You should be able to go to the Schema tab and change the mapping via a drop down.

1 Like

Well, I don't see a drop down, so I assume the first option applies? Though it is rather cumbersome to re-create the index... Also, how can I ensure that the date mapping is created as a date this time around?

Right, that means your mappings don't have the required fields, so you probably created an Elasticsearch backed engine. You can see in the linked docs which features are available for App Search managed engines vs. Elasticsearch engines, and in the latter the schema page can only be used to list the schema and not change it.

Here's where we list the schema field types supported by Elasticsearch backed engines.

For this specific index, you would have to create a new index, specify the mappings you want (in the case of your question, you'd want to specify date fields - I would suggest reviewing your schema to make sure any other date or numeric fields are also appropriately specified). Then you will have to reindex into the new index, and create a new Elasticsearch backed engine off that index.

The alternate approach is to create a new App Search managed engine, and index your documents into that engine. That will allow you to use the schema UI going forward. However, while that's the more flexible approach with App Search overall, my recommendation would be to take the Elasticsearch backed approach unless you absolutely need features in the App Search managed engines. This is the better long term solution as it allows you to manage and search the index very easily outside of the App Search product.

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