# App Search field types with ES based index

**URL:** <https://discuss.elastic.co/t/app-search-field-types-with-es-based-index/355405>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [March 14, 2024, 12:39pm UTC](https://discuss.elastic.co/t/app-search-field-types-with-es-based-index/355405 "2024-03-14T12:39:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chenko](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@Chenko](https://discuss.elastic.co/u/Chenko)\
**Post date:** [March 14, 2024, 12:39pm UTC](https://discuss.elastic.co/t/app-search-field-types-with-es-based-index/355405/1 "2024-03-14T12:39:33Z")

</div>

Hi,

I am running into an issue with App Search, the issue goes like this: I create an ES index with the mappings required for App Search relevance tuning and such.

I create an App Search engine, with the ES based index.

When I go to schema everything is text, even though I have some fields that have dates and such. I cannot change this type.

How would I get these fields to show up as date etc.?

I was thinking this would already have been asked or was in the documentation but I could not find it so apologies if I overlooked this.

Help would be appreciated!

---

<div class="post-metadata">

**Author:** ![Sean\_Story](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_story/32/69987_2.png) [@Sean\_Story](https://discuss.elastic.co/u/Sean_Story)\
**Post date:** [March 14, 2024, 1:09pm UTC](https://discuss.elastic.co/t/app-search-field-types-with-es-based-index/355405/2 "2024-03-14T13:09:36Z")

</div>

@Chenko can you share what your index mappings look like for your date field? I would expect that you're not using `date` or `date_nanos`. Please read the docs for [supported field types in Elasticsearch index engines](https://www.elastic.co/guide/en/app-search/current/elasticsearch-engines.html#elasticsearch-engines-supported-fields)

---

<div class="post-metadata">

**Author:** ![GlebL](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@GlebL](https://discuss.elastic.co/u/GlebL)\
**Post date:** [March 14, 2024, 2:04pm UTC](https://discuss.elastic.co/t/app-search-field-types-with-es-based-index/355405/3 "2024-03-14T14:04:36Z")

</div>

Hello  
the mapping looks like this:

"metadata\_datum": {  
"type": "text",  
"fields": {  
"date": {  
"type": "date",  
"format": "strict\_date\_time||strict\_date",  
"ignore\_malformed": true  
},  
....

The problem is - we cannot sort the search results of the app search query like this:

"sort": [  
{ "metadata\_datum.date": "desc" }  
]

---

<div class="post-metadata">

**Author:** ![Chenko](https://avatars.discourse-cdn.com/v4/letter/c/258eb7/32.png) [@Chenko](https://discuss.elastic.co/u/Chenko)\
**Post date:** [March 14, 2024, 6:30pm UTC](https://discuss.elastic.co/t/app-search-field-types-with-es-based-index/355405/4 "2024-03-14T18:30:28Z")

</div>

> [@GlebL](#):
>
> Hello  
> the mapping looks like this:
> 
> "metadata\_datum": {  
> "type": "text",  
> "fields": {  
> "date": {  
> "type": "date",  
> "format": "strict\_date\_time||strict\_date",  
> "ignore\_malformed": true  
> },  
> ....
> 
> The problem is - we cannot sort the search results of the app search query like this:
> 
> "sort": [  
> { "metadata\_datum.date": "desc" }  
> ]

Hi Sean, Gleb is my colleague. These are indeed the mappings.

---

<div class="post-metadata">

**Author:** ![Sean\_Story](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean_story/32/69987_2.png) [@Sean\_Story](https://discuss.elastic.co/u/Sean_Story)\
**Post date:** [March 14, 2024, 7:38pm UTC](https://discuss.elastic.co/t/app-search-field-types-with-es-based-index/355405/5 "2024-03-14T19:38:30Z")

</div>

@Chenko @GlebL thanks! Ok, I think this makes sense. You're using [multifields](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html). App Search has support for [a specific set of mutlifieds for text fields](https://www.elastic.co/guide/en/app-search/current/elasticsearch-engines-text-subfields-support-conventions.html), but other than those, really looks at top-level fields to determine what should be accessible in the App Search Schema.

While special handling is available for [Object Fields](https://www.elastic.co/guide/en/app-search/current/elasticsearch-engines.html#elasticsearch-engines-object-fields) and [Nested Fields](https://www.elastic.co/guide/en/app-search/current/elasticsearch-engines.html#elasticsearch-engines-nested-fields), it doesn't seem that we can support arbitrary multifields.

However, the big benefit of multifields is that it allows you to store your `_source` once, but analyze it in multiple ways. Another feature that allows this same behavior is `copy_to`, and since this creates a new top-level field instead of a subfield, it seems to work with App Search. I created a minimal example:

```auto
PUT copyto
{
  "mappings": {
    "properties": {
      "metadata_datum" : {
        "type": "text",
        "copy_to": "date"
      },
      "date": {
        "type": "date"
      }
    }
  }
}

POST copyto/_doc/1
{
  "metadata_datum": "2023-01-01"
}

POST copyto/_doc/2
{
  "metadata_datum": "2024-01-01"
}

```

If you then create an App Search Engine from this `copyto` index, you can execute a query like:

```auto
curl -XGET ${HOST}/api/as/v1/engines/copyto/search \
-H "Authorization: Bearer ${KEY}" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
  "query": "",
  "sort": [
    { "date": "asc" }
  ]
}' | jq

```

And it works as expected.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![GlebL](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@GlebL](https://discuss.elastic.co/u/GlebL)\
**Post date:** [March 15, 2024, 9:33am UTC](https://discuss.elastic.co/t/app-search-field-types-with-es-based-index/355405/6 "2024-03-15T09:33:51Z")

</div>

The solution works! Thanks a lot!

---

<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:** [April 12, 2024, 9:34am UTC](https://discuss.elastic.co/t/app-search-field-types-with-es-based-index/355405/7 "2024-04-12T09:34:27Z")

</div>

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