# Completion Suggester not showing results if value is already in previous field

**URL:** https://discuss.elastic.co/t/completion-suggester-not-showing-results-if-value-is-already-in-previous-field/293370
**Category:** Elasticsearch
**Created:** [January 3, 2022, 4:12pm UTC](https://discuss.elastic.co/t/completion-suggester-not-showing-results-if-value-is-already-in-previous-field/293370 "2022-01-03T16:12:13Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![javaman](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@javaman](https://discuss.elastic.co/u/javaman)
#### Post date: [January 3, 2022, 4:12pm UTC](https://discuss.elastic.co/t/completion-suggester-not-showing-results-if-value-is-already-in-previous-field/293370/1 "2022-01-03T16:12:13Z")

</div>

I experience a problem with the completion suggester in Elasticsearch 7.9.1 (also present in 6.7)

If I have more than one suggest input with the same value for different contexts it will only find a completion for the first one, not the second.

The suggest Part of the Document looks like this.

```
"SUGGEST": [
	{
		"input": [
			"Inzidenz",
			"Notbremse",
			"Kraft",
			"Mallorca"
		],
		"contexts": {
			"FIELD": [
				"DESKT",
				"DESKT_ABST"
			]
		}
	},
	{
		"input": [
			"Pandemie",
			"Notbremse",
			"Kraft"
		],
		"contexts": {
			"FIELD": [
				"TIT",
				"TITSPLABST",
				"TITSP",
				"TITTXTSP",
				"TIT_RHTI"
			]
		}
	}
]

```

Both contein the input "Notbremse" But if I search for "Notbre" with the contexts FIELD "TITSPLABST" I get no results. But if I search for "Notbre" with the contexts FIELD "DESKT" i get the expected result. It depends on the order of the input fields in the document. if i change the order that the input field for "TITSPLABST" is before the other then it works.

How to reproduce:  
create index:

```auto
PUT /suggest_test?pretty
{
	"settings" : {
		"index.mapping.nested_fields.limit" : 60,
		
		"number_of_replicas" : 1,
		"number_of_shards" : 6,
		
		"index" : {
			"analysis" : {
				"char_filter" : {
					"umlaut_filter" : {
						"type" : "mapping",
						"mappings" : ["\u00c4=>ae", "\u00e4=>ae", "\u00d6=>oe", "\u00f6=>oe", "\u00dc=>ue", "\u00fc=>ue", "\u00df=>ss", "\u00c6=>Ae", "\u00e6=>ae", "\u00d8=>Oe", "\u00f8=>oe"]
					},
					"underscore_pattern" : {
						"type" : "pattern_replace",
						"pattern" : "\\_",
						"replacement" : ""
					}
				},
				"tokenizer" : {
					"sd_tokenizer" : {
						"type" : "pattern",
						"pattern" : "[^\\p{N}\\p{L}#]+",
						"group" : "-1"
					}
				},
				"filter" : {
					"prefixFilter" : {
				               "type" : "pattern_capture",
				               "preserve_original" : true,
				               "patterns" : [
				                  "([a-zA-Z]+[^#])$"
				               ]
				            }     
				},
				"analyzer" : {
					 "default": {
						"type" : "custom",
						"tokenizer" : "sd_tokenizer",
						"char_filter" : ["umlaut_filter", "underscore_pattern"],
						"filter" : ["lowercase", "asciifolding"]
					},
					"prefixAnalyzer": {
						"tokenizer" : "sd_tokenizer",
						"char_filter" : ["umlaut_filter", "underscore_pattern"],
						"filter" : ["prefixFilter","lowercase", "asciifolding"]
					},
					"same_analyzer": {
						"type" : "custom",
						"tokenizer" : "keyword",
						"char_filter" : ["umlaut_filter", "underscore_pattern"],
						"filter" : ["lowercase", "asciifolding"]
					},
					
					"online_rechte_analyzer": {
						"type" : "custom",
						"tokenizer" : "sd_tokenizer",
						"filter": ["lowercase"]
					}
				}
			}
		}
	},
	"mappings": {
			"_source" : {
				"enabled" : true
			},
			"dynamic" : "strict",
			"properties" : {
				"AK" : {
					"properties" : {
						"TITLE" : {
							"type" : "text"
						},
						"TEXT" : {
							"type" : "text"
						}
				}
			},
			"SUGGEST": {
					"type": "completion",
					"analyzer": "default",
					"preserve_separators": true,
					"preserve_position_increments": true,
					"max_input_length": 25,
					"contexts": [
						{
							"name": "FIELD",
							"type": "category"
						}
					]
			}  
		}
	}
}

```

Put Document in it:

```auto
POST /suggest_test/_doc?refresh=true
{
	"AK": [
		{
			"TITLE": "Die Notbremse tritt in Kraft",
			"TEXT": [
				"Inzidenz von 99,9, ab 100 soll die vereinbarte 'Notbremse' in Kraft treten.\n\n(O-Ton) Angela Merkel: \"Werden leider von der Notbremse Gebrauch machen muessen\" \n(O-Ton) Michael Kretschmer: Schnell umsteuern \n(O-Ton) Malu Dreyer: Oeffnung Aussengastronomie bei Kontaktbeeschraenkungen \n(O-Ton) Manuela Schwesig: Contro Reisen nach Mallorca, aber nicht im eigenen Bundesland \n(O-Ton) Angela Merkel: \"Devise lautet: Impfen, impfen, impfen \n(O-Ton) Ulrich Weigelt: Die Menschen moechten beim Hausarzt geimpft werden \n(O-Ton) Manuela Schwesig: (Impfstoff Sputnik V) Impfstoff muss sicher sein, Herkunft darf nicht entscheidend sein"
			]
		}
	],
	"SUGGEST": [
		{
			"input": [
				"Inzidenz",
				"Notbremse",
				"Kraft",
				"Mallorca"
			],
			"contexts": {
				"FIELD": [
					"DESKT",
					"DESKT_ABST"
				]
			}
		},
		{
			"input": [
				"Pandemie",
				"Notbremse",
				"Kraft"
			],
			"contexts": {
				"FIELD": [
					"TIT",
					"TITSPLABST",
					"TITSP",
					"TITTXTSP",
					"TIT_RHTI"
				]
			}
		}
	]
}

```

Search for completion of "Notbrem" in contexts FIELD TITSPLABST (TITSPLABST is just a name from the Java context)

```auto
POST suggest_test/_search?pretty
{
    "suggest": {
        "hfdb-suggest" : {
            "prefix" : "Notbrem", 
            "completion" : { 
                "field" : "SUGGEST" ,"skip_duplicates":false,"contexts":{
          "FIELD":[{"context":"TITSPLABST","boost":1}]
        }
            }
        }
    }
}

```

no result

Now search for "Notbrem" in contexts FFIELD DESKT

```auto
POST suggest_test/_search?pretty
{
    "suggest": {
        "hfdb-suggest" : {
            "prefix" : "Notbrem", 
            "completion" : { 
                "field" : "SUGGEST" ,"skip_duplicates":false,"contexts":{
          "FIELD":[{"context":"DESKT","boost":1}]
        }
            }
        }
    }
}

```

Now I get a result.

I expected a result in the first query but didn't get one.  
Could anybody please help me with this issue?

And if i missed some needed information i could provide it here.

---

<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: [January 31, 2022, 4:12pm UTC](https://discuss.elastic.co/t/completion-suggester-not-showing-results-if-value-is-already-in-previous-field/293370/2 "2022-01-31T16:12:46Z")

</div>

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