# Trying to make search like \`procter&gamble\` and \`procter & gamble\` work the same way

**URL:** <https://discuss.elastic.co/t/trying-to-make-search-like-procter-gamble-and-procter-gamble-work-the-same-way/231961>\
**Category:** Elasticsearch\
**Created:** [May 11, 2020, 9:01am UTC](https://discuss.elastic.co/t/trying-to-make-search-like-procter-gamble-and-procter-gamble-work-the-same-way/231961 "2020-05-11T09:01:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AHeavyObject](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aheavyobject/32/68052_2.png) [@AHeavyObject](https://discuss.elastic.co/u/AHeavyObject)\
**Post date:** [May 11, 2020, 9:01am UTC](https://discuss.elastic.co/t/trying-to-make-search-like-procter-gamble-and-procter-gamble-work-the-same-way/231961/1 "2020-05-11T09:01:50Z")

</div>

My task is:

- Make `procter&gamble` and `procter & gamble` produce the same results including score
- Make it universal, not via synonyms, as it can be any other `Somehow&Somewhat`
- Highlight `procter&gamble` or `procter & gamble`, not separate tokens if the phrase matches
- I want to use `simple_query_string`as I allow search operators
- Make `AT&T` searchable as well

Here is my snippet. The problems that `procter&gamble` or `procter & gamble` searches produce different scores and this different documents as the result.  
But the user expects the same result for `procter&gamble` or `procter & gamble`

```auto
DELETE /english_example
PUT /english_example
{
  "settings": {
    "analysis": {
      "filter": {
        "english_stop": {
          "type": "stop",
          "stopwords": "_english_" 
        },
        "english_keywords": {
          "type": "keyword_marker",
          "keywords": ["example"] 
        },
        "english_stemmer": {
          "type": "stemmer",
          "language": "english"
        },
        "english_possessive_stemmer": {
          "type": "stemmer",
          "language": "possessive_english"
        },
        "acronymns": {
          "type": "word_delimiter_graph",
          "catenate_all" : true,
          "preserve_original":true
        },
        "acronymns_": {
          "type": "word_delimiter_graph",
          "catenate_all" : true,
          "preserve_original":true
        },
        "custom_stop_words_filter": {
          "type": "stop",
          "ignore_case": true,
          "stopwords": ["t"]
        }
        
      },
      "analyzer": {
        "default": {
          "tokenizer": "whitespace",
          "char_filter": [
           "ampersand_filter"
          ],
          "filter": [
            "english_possessive_stemmer",
            "lowercase",
            "acronymns",
            "flatten_graph",
            "english_stop",
            "custom_stop_words_filter",
            "english_keywords",
            "english_stemmer"
          ]
        }
      },
      "char_filter": {
        "ampersand_filter": {
          "type": "pattern_replace",
          "pattern": "(?=[^&]*)( {0,}& {0,})(?=[^&]*)",
          "replacement": "_and_"
        },
        "ampersand_filter2": {
          "type": "mapping",
          "mappings": [
            "& => _and_"
          ]
        }
      }
    }
  }
}
PUT /english_example/_bulk 
{ "index" : { "_id" : "1" } }
{ "description" : "wi-fi AT&T BB&T Procter & Gamble, some\nOther $500 games with Peter's", "contents" : "Much text with somewhere I meet Procter or Gamble" }
{ "index" : { "_id" : "2" } }
{ "description" : "Procter & Gamble", "contents" : "Much text with somewhere I meet Procter and Gamble" }
{ "index" : { "_id" : "3" } }
{ "description" : "Procter&Gamble", "contents" : "Much text with somewhere I meet Procter & Gamble" }
{ "index" : { "_id" : "4" } }
{ "description" : "Come Procter&Gamble", "contents" : "Much text with somewhere I meet Procter&Gamble" }
{ "index" : { "_id" : "5" } }
{ "description" : "Tome Procter & Gamble", "contents" : "Much text with somewhere I don't meet AT&T" }

# "query": "procter & gamble",
GET english_example/_search
{
    "query": {
      "simple_query_string": {
          "query": "procter & gamble",
          "default_operator": "or",
          "fields": [
            "description^2",
            "contents^80"
          ]
      }
    },
    "highlight": {
      "fields": {
        "description": {},
        "contents": {}
      }
    }
}

# "query": "procter&gamble",
GET english_example/_search
{
    "query": {
      "simple_query_string": {
          "query": "procter&gamble",
          "default_operator": "or",
          "fields": [
            "description^2",
            "contents^80"
          ]
      }
    },
    "highlight": {
      "fields": {
        "description": {},
        "contents": {}
      }
    }
}

# "query": "at&t",
GET english_example/_search
{
    "query": {
      "simple_query_string": {
          "query": "at&t",
          "default_operator": "or",
          "fields": [
            "description^2",
            "contents^80"
          ]
      }
    },
    "highlight": {
      "fields": {
        "description": {},
        "contents": {}
      }
    }
}

```

---

<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:** [June 8, 2020, 9:01am UTC](https://discuss.elastic.co/t/trying-to-make-search-like-procter-gamble-and-procter-gamble-work-the-same-way/231961/2 "2020-06-08T09:01:52Z")

</div>

Closed on June 8, 2020, 9:01am UTC

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