App Search field types with ES based index

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!

@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

1 Like

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.

@Chenko @GlebL thanks! Ok, I think this makes sense. You're using multifields. App Search has support for a specific set of mutlifieds for text fields, 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 and 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:

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:

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!

1 Like

The solution works! Thanks a lot!

1 Like

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