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

Specify serialization for a field inside a Document #1

Closed
anti-social opened this issue Sep 15, 2021 · 4 comments
Closed

Specify serialization for a field inside a Document #1

anti-social opened this issue Sep 15, 2021 · 4 comments
Labels
hardcore A lot of work questionable Do we really need it?

Comments

@anti-social
Copy link
Owner

anti-social commented Sep 15, 2021

At the moment Document describes Elasticsearch field types:

object UserDoc : Document() {
    // Elasticsearch doesn't have separate list type, almost all types are multi-valued
    val groups by keyword()
}

And concrete serialization is specified inside a document source:

class User : DocSource() {
    // Here `groups` value deserializes into a list of keywords
    val goups by UserDoc.groups.list()
}

Consider to specify serialization when describing a Document:

object UserDoc : Document() {
    // When generating a mapping it will be just a `keyword` type
    val groups by keyword().list()
}

class User : DocSource() {
    // Document source should take into account that it is a list of keywords
    val groups by UserDoc.groups
}
@anti-social
Copy link
Owner Author

Think it is not possible. The problem appears when dealing with sub-documents and sub-fields:

class NameSubFields<V>(field: BoundField<V>) : SubFields<V>(field) {
    val sort by keyword()
}

Now imagine these variants:

object ProductDoc : Document() {
    val name: NameSubFields<String?> by text().subFields(::NameSubFields)
}
object ProductDocV2 : Document() {
    // `::NameSubFields` has type of `(BoundField<String>) -> NameSubFields<String?>`
    val name: NameSubFields<String> by text().subFields(::NameSubFields)
        // What type should return `required`? We cannot transform `NameSubFields<String?>` into `NameSubFields<String>`
        .required()
}

@anti-social
Copy link
Owner Author

An example how it could be implemented: https://gist.github.com/anti-social/1a36d715ca8d8080c56a84bda0af2cc8

@anti-social
Copy link
Owner Author

anti-social commented Sep 23, 2021

Such a scheme has some drawbacks:

  • we cannot generate document source from a mapping. Do we really need it?
  • also there could be multiple document types with common mapping

@anti-social anti-social added the questionable Do we really need it? label Sep 23, 2021
@anti-social
Copy link
Owner Author

#45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hardcore A lot of work questionable Do we really need it?
Projects
None yet
Development

No branches or pull requests

1 participant