# Не работают стоп слова

**URL:** https://discuss.elastic.co/t/topic/247972
**Category:** Вопросы на русском языке
**Created:** [September 9, 2020, 7:49am UTC](https://discuss.elastic.co/t/topic/247972 "2020-09-09T07:49:55Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Ivan\_Filonenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivan_filonenko/32/75290_2.png) [@Ivan\_Filonenko](https://discuss.elastic.co/u/Ivan_Filonenko)
#### Post date: [September 9, 2020, 7:49am UTC](https://discuss.elastic.co/t/topic/247972/1 "2020-09-09T07:49:55Z")

</div>

Continuing the discussion from [Не работают стоп слова](https://discuss.elastic.co/t/topic/50696):

У меня схожая проблема, что и описанная выше. Только в индексе есть все нужные настройки, а поиск все равно осуществляется без стоп-слов.

Вот так выглядят настройки:

```auto
$settings = [
		    'number_of_shards' => 1,
		    'number_of_replicas' => 1,
		    'max_ngram_diff' => 50,
		    'analysis' => [
			    'analyzer' => [
				    'custom_analyzer' => [
					    'type' => 'custom',
					    'char_filter' => ['e_char_filter'],
					    'tokenizer' => 'nGram',
					    'filter' => ['stopwords', 'ru_stopwords', 'asciifolding' ,'lowercase', 'snowball'],
				    ],
				    'custom_search_analyzer' => [
					    'type' => 'custom',
					    'char_filter' => ['e_char_filter'],
					    'tokenizer' => 'standard',
					    'filter' => ['stopwords', 'ru_stopwords', 'asciifolding' ,'lowercase', 'snowball'],
				    ],
			    ],
			    'tokenizer' => [
				    'nGram' => [
					    'type' => 'nGram',
					    'min_gram' => 2,
					    'max_gram' => 20,
				    ],
			    ],
			    'filter' => [
				    'snowball' => [
					    'type' => 'snowball',
					    'language' => 'Russian',
				    ],
				    'stopwords' => [
					    'type' => 'stop',
					    'stopwords' => '_russian_',
					    'ignore_case' => 'true',
				    ],
				    'ru_stopwords' => [
					    'type' => 'stop',
					    'stopwords' => 'рецепт'
				    ],
			    ],
			    'char_filter' => [
				    'e_char_filter'=> [
					    'type'=> 'mapping',
				       'mappings'=> ['Ё => Е', 'ё => е']
				    ]
			    ]
		    ],
	    ];

```

вот так индексация:

```auto
$category = [
		    'index' => 'category',
		    'body' => [
			    'settings' => $settings,
					'mappings' => [
						'_source' => [
							'enabled' => true,
						],
						'properties' => [
							'name' => [
								'type' => 'text',
								'analyzer' => 'custom_analyzer',
								'search_analyzer' => 'custom_search_analyzer',
							],
							'url' => [
								'type' => 'text',
								'analyzer' => 'custom_analyzer',
								'search_analyzer' => 'custom_search_analyzer',
							],
							'id' => [
								'type' => 'integer'
							]
						]
					],
		    ]
	    ];

```

версия эластика  
`7.8.0`

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [September 9, 2020, 4:59pm UTC](https://discuss.elastic.co/t/topic/247972/2 "2020-09-09T16:59:37Z")

</div>

Вы не могли бы перевести эти настройки в json, чтобы я мог попробовать с ними поработать. И у вас в индексации тоже настройки вместо документа, а запроса вообще нет.

---

<div class="post-metadata">

### Author: ![Ivan\_Filonenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivan_filonenko/32/75290_2.png) [@Ivan\_Filonenko](https://discuss.elastic.co/u/Ivan_Filonenko)
#### Post date: [September 10, 2020, 5:29am UTC](https://discuss.elastic.co/t/topic/247972/3 "2020-09-10T05:29:10Z")

</div>

```auto
{
"index":"category",
"body":{
"settings":{
"number_of_shards":1,
"number_of_replicas":1,
"max_ngram_diff":50,
"analysis":{
"analyzer":{
"custom_analyzer":{
"type":"custom",
"char_filter":[
"e_char_filter"
],
"tokenizer":"nGram",
"filter":[
"stopwords",
"ru_stopwords",
"asciifolding",
"lowercase",
"snowball"
]
},
"custom_search_analyzer":{
"type":"custom",
"char_filter":[
"e_char_filter"
],
"tokenizer":"standard",
"filter":[
"stopwords",
"ru_stopwords",
"asciifolding",
"lowercase",
"snowball"
]
}
},
"tokenizer":{
"nGram":{
"type":"nGram",
"min_gram":2,
"max_gram":20
}
},
"filter":{
"snowball":{
"type":"snowball",
"language":"Russian"
},
"stopwords":{
"type":"stop",
"stopwords":"_russian_",
"ignore_case":"true"
},
"ru_stopwords":{
"type":"stop",
"stopwords":"рецепт"
}
},
"char_filter":{
"e_char_filter":{
"type":"mapping",
"mappings":[
"Ё => Е",
"ё => е"
]
}
}
}
},
"mappings":{
"_source":{
"enabled":true
},
"properties":{
"name":{
"type":"text",
"analyzer":"custom_analyzer",
"search_analyzer":"custom_search_analyzer"
},
"url":{
"type":"text",
"analyzer":"custom_analyzer",
"search_analyzer":"custom_search_analyzer"
},
"id":{
"type":"integer"
}
}
}
}
}

```

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [September 10, 2020, 6:19pm UTC](https://discuss.elastic.co/t/topic/247972/4 "2020-09-10T18:19:16Z")

</div>

И пример того, как они не работают?

---

<div class="post-metadata">

### Author: ![Ivan\_Filonenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivan_filonenko/32/75290_2.png) [@Ivan\_Filonenko](https://discuss.elastic.co/u/Ivan_Filonenko)
#### Post date: [September 11, 2020, 11:38am UTC](https://discuss.elastic.co/t/topic/247972/5 "2020-09-11T11:38:38Z")

</div>

```auto
{

 "index":"categories",
 "body":{
  "sort":"_score",
  "size":10,
  "query":{
     "bool":{
       "must":{
         "multi_match":{
           "fields":["name"],
          "query":"query"
     }
   }
 }
 }
}
}

```

вот пример запроса:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/2/f2b90e7e8d838cf92c1081ffd817a9c8ae6a6b24.png)

Ищет не учитывая стоп слово "с".

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [September 15, 2020, 2:28pm UTC](https://discuss.elastic.co/t/topic/247972/6 "2020-09-15T14:28:48Z")

</div>

Пытаюсь воспроизвести:

```auto
DELETE test

PUT test
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 1,
    "max_ngram_diff": 50,
    "analysis": {
      "analyzer": {
        "custom_analyzer": {
          "type": "custom",
          "char_filter": [
            "e_char_filter"
          ],
          "tokenizer": "nGram",
          "filter": [
            "stopwords",
            "ru_stopwords",
            "asciifolding",
            "lowercase",
            "snowball"
          ]
        },
        "custom_search_analyzer": {
          "type": "custom",
          "char_filter": [
            "e_char_filter"
          ],
          "tokenizer": "standard",
          "filter": [
            "stopwords",
            "ru_stopwords",
            "asciifolding",
            "lowercase",
            "snowball"
          ]
        }
      },
      "tokenizer": {
        "nGram": {
          "type": "nGram",
          "min_gram": 2,
          "max_gram": 20
        }
      },
      "filter": {
        "snowball": {
          "type": "snowball",
          "language": "Russian"
        },
        "stopwords": {
          "type": "stop",
          "stopwords": "_russian_",
          "ignore_case": "true"
        },
        "ru_stopwords": {
          "type": "stop",
          "stopwords": "рецепт"
        }
      },
      "char_filter": {
        "e_char_filter": {
          "type": "mapping",
          "mappings": [
            "Ё => Е",
            "ё => е"
          ]
        }
      }
    }
  },
  "mappings": {
    "_source": {
      "enabled": true
    },
    "properties": {
      "name": {
        "type": "text",
        "analyzer": "custom_analyzer",
        "search_analyzer": "custom_search_analyzer"
      },
      "url": {
        "type": "text",
        "analyzer": "custom_analyzer",
        "search_analyzer": "custom_search_analyzer"
      },
      "id": {
        "type": "integer"
      }
    }
  }
}

POST test/_bulk
{ "index" : {} }
{ "name" : "Булочки с овощами" }
{ "index" : {} }
{ "name" : "Булочки" }
{ "index" : {} }
{ "name" : "Постные булочки дрожжевые" }
{ "index" : {} }
{ "name" : "Салаты с курицей" }
{ "index" : {} }
{ "name" : "Рис с овощами" }

GET test/_search
{
  "sort": "_score",
  "size": 10,
  "query": {
    "bool": {
      "must": {
        "multi_match": {
          "fields": [
            "name"
          ],
          "query": "Булочки с овощами"
        }
      }
    }
  }
}

```

Получаю:

```auto
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 4,
      "relation" : "eq"
    },
    "max_score" : 2.2175546,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "6v4kknQBgqoXz1_P9du_",
        "_score" : 2.2175546,
        "_source" : {
          "name" : "Булочки с овощами"
        }
      },
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "7v4kknQBgqoXz1_P9du_",
        "_score" : 1.5916679,
        "_source" : {
          "name" : "Рис с овощами"
        }
      },
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "6_4kknQBgqoXz1_P9du_",
        "_score" : 0.9682747,
        "_source" : {
          "name" : "Булочки"
        }
      },
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "7P4kknQBgqoXz1_P9du_",
        "_score" : 0.55274975,
        "_source" : {
          "name" : "Постные булочки дрожжевые"
        }
      }
    ]
  }
}

```

Все работает, как я бы и ожидал. Вы не могли бы помочь вам помочь и привести полный пример, который я мог бы запустить и посмотреть, что не работает?

---

<div class="post-metadata">

### Author: ![Ivan\_Filonenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivan_filonenko/32/75290_2.png) [@Ivan\_Filonenko](https://discuss.elastic.co/u/Ivan_Filonenko)
#### Post date: [September 17, 2020, 8:38am UTC](https://discuss.elastic.co/t/topic/247972/7 "2020-09-17T08:38:41Z")

</div>

В целом, это и есть полный поисковый запрос. У меня это выглядит вот так:

```auto
$params = [
			'index' => 'categories',
			'body' => [
				'sort' => '_score',
				'size' => isset($limit) ? $limit : 10,
				'query' => [
					'bool' => [
						'must' => [
							'multi_match' => [
								'fields' => ['name'],
								'query' => $query,
							],
						],
					],
				],
			]
		];

		$response = $this->client->search($params);

```

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [September 17, 2020, 3:02pm UTC](https://discuss.elastic.co/t/topic/247972/8 "2020-09-17T15:02:59Z")

</div>

Этот запрос работает. Значит проблема, где-то в другом месте, проверьте настройки и исправьте, пожалуйста, мой пример, что бы он не работал, как у вас.

---

<div class="post-metadata">

### Author: ![Ivan\_Filonenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivan_filonenko/32/75290_2.png) [@Ivan\_Filonenko](https://discuss.elastic.co/u/Ivan_Filonenko)
#### Post date: [September 18, 2020, 8:17am UTC](https://discuss.elastic.co/t/topic/247972/9 "2020-09-18T08:17:59Z")

</div>

А на какой версии эластика вы все это пробуете?  
Просто я уже не представляю куда смотреть. Все возможные варианты испробовал.  
В каком месте может быть ошибка?  
Если индекс собран правильно, запрос составлен тоже корректно?

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [September 18, 2020, 4:20pm UTC](https://discuss.elastic.co/t/topic/247972/10 "2020-09-18T16:20:02Z")

</div>

> [@Ivan\_Filonenko](#):
>
> А на какой версии эластика вы все это пробуете?

7.8.0 Вы мой пример на вашей версии запускали?

> [@Ivan\_Filonenko](#):
>
> Если индекс собран правильно, запрос составлен тоже корректно?

Скорее всего, что-то что вы думаете, что что-то оно правильно, а на самом деле оно не правильно.

---

<div class="post-metadata">

### Author: ![Ivan\_Filonenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ivan_filonenko/32/75290_2.png) [@Ivan\_Filonenko](https://discuss.elastic.co/u/Ivan_Filonenko)
#### Post date: [September 21, 2020, 8:36am UTC](https://discuss.elastic.co/t/topic/247972/11 "2020-09-21T08:36:38Z")

</div>

В общем, проблема была где-то в индексации. На стороне php клиента. Спасибо за помощь!

---

<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: [October 19, 2020, 8:36am UTC](https://discuss.elastic.co/t/topic/247972/12 "2020-10-19T08:36:42Z")

</div>

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