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

Creating an Elasticseearch index with index sorting via Spring annotation #1716

Closed
strokine opened this issue Mar 4, 2021 · 2 comments
Closed
Labels
type: enhancement A general enhancement

Comments

@strokine
Copy link

strokine commented Mar 4, 2021

I'm using Spring Data for Elasticsearch. I need to create an index with an index sorting as it is described here

There is no way to define a POJO field to be used as a sorting field during indexing

Reply from P.J.Meisch:
Currently this is not possible. Index sorting must be defined when the index is created, and as it is currently possible to define a json file with index settings and add that with @setting to the entity, this fails in this case. The reason is, that when an index sorting is defined, the corresponding field must be defined in the mappings definition on index creation as well. Spring Data Elasticsearch first creates the index with the settings and after that it writes the mappings - which then is too late.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 4, 2021
@sothawo sothawo added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 4, 2021
@sothawo
Copy link
Collaborator

sothawo commented Mar 4, 2021

Note.: This is basically a two step thing:

  1. add a method IndexOperations.createWithMapping() (different variants for providing mapping and settings) that will create an index with settings and mappings in one single call. This is needed for being able to have index sorting and would rely on the setting being provided as a json file (like it is actually already possible) (issue Create index with mapping in one step #1718).
  2. Extend the existing @Setting annotation to take settings parameters, for example the index sorting values. We could also move the existing index settings parameters from the @Document annotation. This would allow for a configuration without using json files (issue Configure index settings with @Setting annotation #1719).

@sothawo
Copy link
Collaborator

sothawo commented Mar 28, 2021

#1718 and #1719 are implemented, it now is possible to define the settings like this:

@Document(indexName = "entities")
@Setting(
  sortFields = { "secondField", "firstField" },
  sortModes = { Setting.SortMode.max, Setting.SortMode.min },
  sortOrders = { Setting.SortOrder.desc, Setting.SortOrder.asc },
  sortMissingValues = { Setting.SortMissing._last, Setting.SortMissing._first })
class Entity {
    @Nullable
    @Id private String id;

    @Nullable
    @Field(type = FieldType.Keyword)
    private String firstField;

    @Nullable @Field(type = FieldType.Keyword)
    private String secondField;

    // getter and setter...
}

will be contained in the next release 4.2.0.RC1

@sothawo sothawo closed this as completed Mar 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants