Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow alias in "fields" in _mapping #96817

Closed
linker-c opened this issue Jun 13, 2023 · 8 comments
Closed

Allow alias in "fields" in _mapping #96817

linker-c opened this issue Jun 13, 2023 · 8 comments
Labels
>enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Comments

@linker-c
Copy link

Description

It would be good to allow alias (or auto aliasing) if there are duplicate type attribute for a given field.

We often turn a "text" field into "keyword" because whole string matching is all we need.
A good example would be UUID or model (list of 5 possible models, etc)
There is really no reason to do a partial UUID search. It doesn't make sense (at least for our application).
So the most efficient way to define the mapping for this field would be "keyword".
This creates a potential issue for the caller with inconsistent query string. The caller needs to know if a field is a text or keyword natively.

Ex1:
Query string of "model" = "iPhone" vs "model.keyword" = "iPhone" is the difference here, depending on what "model" is defined as.

Ex2:

{
  "myindex" : {
    "mappings" : {
      "properties" : {
        "Username" : {. // searchable label
          "type" : "text",
          "fields" : {
            "keyword" : {. // incase the caller wants exact matching
              "type" : "keyword"
            }
         }
       },
        "Username_id" : {. // UUID record for this user
          "type" : "keyword",
          "fields" : {
            "keyword" : {
              "type" : "keyword"
            }
         }
       }
     }
   }
  }
}

From the above ex2, our practice has been add dot_keyword to "fields" for "Username_id" so the caller can have a consistent query pattern. Always use "label.keyword" for exact matching...

I just learned that this approach will cause 2 reverse index to be created for "Username_id" even though they are identical.

This feature request is to allow such duplicate "type" be specified via alias so we don't introduce unnecessary index for the convenience of standardizing namespaces.

@linker-c linker-c added >enhancement needs:triage Requires assignment of a team area label labels Jun 13, 2023
@gmarouli gmarouli added :Search Foundations/Mapping Index mappings, including merging and defining field types and removed needs:triage Requires assignment of a team area label labels Jun 14, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@elasticsearchmachine elasticsearchmachine added the Team:Search Meta label for search team label Jun 14, 2023
@javanna
Copy link
Member

javanna commented Jun 20, 2023

heya @linker-c mappings already support field aliases, see https://www.elastic.co/guide/en/elasticsearch/reference/current/field-alias.html .

I believe if all you are looking for is two field names to point to the same inverted index, field aliases will be the solution.

@javanna javanna closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2023
@linker-c
Copy link
Author

linker-c commented Jun 21, 2023

It doesn't work @javanna. I am not trying to point one field to another. I'm trying to point label.keyword to label itself.

PUT testing
{
  "mappings": {
    "properties": {
      "my_uuid": {
        "type": "keyword",
        "fields": {
          "keyword": {
            "type": "alias",
            "path":"my_uuid"
          }
        }
      }
    }
  }
}

{
  "error" : {
    "root_cause" : [
      {
        "type" : "mapper_parsing_exception",
        "reason" : "Type [alias] cannot be used in multi field"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [_doc]: Type [alias] cannot be used in multi field",
    "caused_by" : {
      "type" : "mapper_parsing_exception",
      "reason" : "Type [alias] cannot be used in multi field"
    }
  },
  "status" : 400
}

@javanna
Copy link
Member

javanna commented Jun 21, 2023

Oh I see this interferes with the fact that they are in the same multi-field. You could do this through a runtime field. This is somehow related to #87969 . If field aliases were implemented as runtime fields internally, you would not have run into this problem. The workaround is to define a runtime field with a small script that loads the field that you want to alias.

@linker-c
Copy link
Author

Thanks @javanna. Can you give me an example of how to do this with my simple example? If I understand you correctly, I'll need to create a new field which is kind of similar to your original suggestions.
My intend is to allow the API query to be agnostic about the "string" field.

@linker-c
Copy link
Author

Can you please reopen this feature request since there's really no equivalent function to what I am looking for?
Thanks.

@javanna
Copy link
Member

javanna commented Jun 26, 2023

The equivalent functionality is a runtime field that extracts the value from the indexed field that you want to alias. Have you tried that?

#87969 will make this possible directly with an alias field.

@linker-c
Copy link
Author

Thanks for the suggestion. I did a little bit research on runtime fields. it seems to equate to scripting.
Unfortunately, we don't allow scripting in our ES cluster. It's too difficult to debug and prone to catastrophic errors.
I understand the potential flexibility, but the risk is just too high.
Anyway, my suggestion/request is to eliminate the need to have duplicate reverse indices simply because of multi-fields. That's kind of a waste for no reason. Each "var" should simply keep one unique index type.

@javanna javanna added Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch and removed Team:Search Meta label for search team labels Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch
Projects
None yet
Development

No branches or pull requests

4 participants