# Filtering data before search

**URL:** <https://discuss.elastic.co/t/filtering-data-before-search/288409>\
**Category:** Elasticsearch\
**Created:** [November 4, 2021, 12:51pm UTC](https://discuss.elastic.co/t/filtering-data-before-search/288409 "2021-11-04T12:51:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor\_Dusautois](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/victor_dusautois/32/96721_2.png) [@Victor\_Dusautois](https://discuss.elastic.co/u/Victor_Dusautois)\
**Post date:** [November 4, 2021, 12:51pm UTC](https://discuss.elastic.co/t/filtering-data-before-search/288409/1 "2021-11-04T12:51:55Z")

</div>

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:

```json
[
{
    "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

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

```

produces (rightfully):

```auto
{
    "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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 4, 2021, 1:45pm UTC](https://discuss.elastic.co/t/filtering-data-before-search/288409/2 "2021-11-04T13:45:53Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). 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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 2, 2021, 1:46pm UTC](https://discuss.elastic.co/t/filtering-data-before-search/288409/3 "2021-12-02T13:46:45Z")

</div>

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