Skip to content

[elasticsearch] Missing .keyword field mapping for String fields #29311

Open
@OmarHawk

Description

@OmarHawk
Overview of the issue

In #22154 an explicit elasticsearch mapping was introduced in order to avoid elasticsearch autodetection of datatype. While this works well, in the default case, a normal String field would normally receive additionally a .keyword field that can then being used for stuff like sorting or equality match until 256 chars.

https://www.elastic.co/docs/manage-data/data-store/mapping/dynamic-field-mapping#dynamic-field-mapping

With the change in that issue, the keyword field is missing, which is in the first place unexpected as it deviates from what you'd get normally.

Motivation for or Use Case

Sticking more to how the index would look like in the standard case making it easier for building stuff on top.

Reproduce the error
Related issues

#22154 #26712

Suggest a Fix

Place an annotation like this on standard String fields (already tried it in a sample application and works like a charm)

    @org.springframework.data.elasticsearch.annotations.MultiField(
        mainField = @org.springframework.data.elasticsearch.annotations.Field(type = org.springframework.data.elasticsearch.annotations.FieldType.Text),
        otherFields = { 
            @InnerField(suffix = "keyword", type = org.springframework.data.elasticsearch.annotations.FieldType.Keyword) 
        }
    )

I'll prepare a PR and let it up to discussion, if we should include this change, but I'd vote for it: The change itself just extends the mapping, so there are no backwards compatibility issues to be expected - if one would want to make use of that .keyword field, one would need to recreate the index of course.

JHipster Version(s)

8.10.0

Browsers and Operating System
  • Tickets opened without reproduction steps or that doesn't follows the template recommendation will be closed.
  • This issue is prompt-related or an error that prevents JHipster from generating an application.
  • I don't have a JDL otherwise I should open an JDL Issue
  • The application is not successfully generated otherwise, I should open an Issue with jhipster info
  • Checking this box is mandatory (this is just to show you read everything)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions