Skip to content

[Elasticsearch] different mapping for patter matching vs. simple value, range, comparison, order by #258

@dkarlovi

Description

@dkarlovi

Description

Elasticsearch only supports full-text search on fields which are analyzed. But, they only allow other operations (like on fields which are not analyzed.

For string based types, the field sorted on should not be analyzed / tokenized.

Elasticsearch solves this by allowing you to define a special fields hash for each property which you can use to add multiple types to the same property.

But, since the fields is optional and there's no "default" which covers all use cases, this means we need to allow the user to specify both somehow.

Example

If we have a field called username which is textual, we could define it like this

{
    "mappings": {
        "_doc": {
            "properties": {
                "username": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword"
                        }
                    }
                }
            }
        }
    }
}

So, if we want to sort by the field or do an exact match (simple value), we would map like this:

username: #username.keyword

If we want to do pattern matching (full text), we would map like this:

username: #username

This means the split of mapping is not really "search & filter" vs "order" (as we concluded in #241), it's actually "search" vs "filter & order". I still think having ordering mapping be "special" is OK since it allows us to have separate contexual conditions applied only when sorting (which is used by has_child order), we only need to figure out how to best allow this type of mapping and not make a mess of the API.

TLDR we need an additional property in a single mapping.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions