Filtering data before search

Hello,
I am trying what I thought was going to be an easy fix with Elasticsearch. It appears I'm stumbling on achieving a sort on a simple name field containing civility:
Here is some sample (fake) data:

[
{
    "name":"Mr and Mrs Smith John"
},
{
    "name":"Mr Doe"
},
{
    "name":"Miss Black and sons"
},
{
    "name":"Mrs White, Snow"
},
{
    "name":"Mrs White, Mary"
}
]

Purpose of the task I'm assigned to is to sort on name regardless of civility, which I thought I could do by using a text field, with a custom analyser with standard tokenize and custom stop filter with various options for civility.
Trouble I'm having is due to the fact that apply a stop filter is returning several tokens, not one.

POST /_analyse

{
    "tokenizer": "standard",
    "filter": [
        {
            "type": "stop",
            "ignore_case": true,
            "stopwords": [
                "mr",
                "mrs",
                "miss"
                "and"
            ]
        }
    ],
    "text": "Mr and Mrs Smith John"
}

produces (rightfully):

{
    "tokens": [
        {
            "token": "Smith",
            "start_offset": 11,
            "end_offset": 16,
            "type": "<ALPHANUM>",
            "position": 3
        },
        {
            "token": "John",
            "start_offset": 17,
            "end_offset": 21,
            "type": "<ALPHANUM>",
            "position": 4
        }
    ]
}

Then applying a sort, this document is retrieved under John, not Smith.
I have been looking for a another filter to combine all tokens into one bu without any luck so far.

I'd appreciate any help or pointer on how to achieve that!
Thanks

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can copy and paste in Kibana dev console, click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.