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

**URL:** https://discuss.elastic.co/t/topic/50696
**Category:** Вопросы на русском языке
**Created:** [May 23, 2016, 10:52am UTC](https://discuss.elastic.co/t/topic/50696 "2016-05-23T10:52:58Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![dasha](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dasha](https://discuss.elastic.co/u/dasha)
#### Post date: [May 23, 2016, 10:52am UTC](https://discuss.elastic.co/t/topic/50696/1 "2016-05-23T10:52:58Z")

</div>

Я использую elasticsearch php.  
первоначальный маппинг выглядит так

```auto
$params = [
    'index' => 'myindex',
    'type' => 'faq_article',
    'body' => [
        'settings' => [
            'analysis' => [
                'char_filter' => [
                    'ru' => [
                        'type' => 'mapping',
                        'mappings' => ['Ё=>Е', 'ё=>е']
                    ],
                ],
                'analyzer' => [
                    'app_index_analyzer' => [
                        'type' => 'custom',
                        'tokenizer' => 'standard',
                        'char_filter' => ['ru', 'html_strip'],
                        'filter' => ['lowercase', 'stop', 'russian_morphology', 'english_morphology']
                    ],
                    'app_search_analyzer' => [
                        'type' => 'custom',
                        'tokenizer' => 'standard',
                        'char_filter' => ['ru', 'html_strip'],
                        'filter' => ['lowercase', 'stop', 'russian_morphology', 'english_morphology']
                    ]
                ],
            ],
            'filter' => [
                'stop' => [
                    'type' => 'stop',
                    'stopwords' => ['как','а','без','более','бы','был','была','были','было','быть','в','вам','вас','весь','во','вот','все','всего','всех','вы','где','да','даже','для','до','его','ее','если','есть','еще','же','за','здесь','и','из','или','им','их','к','как','ко','когда','кто','ли','либо','мне','может','мы','на','надо','наш','не','него','нее','нет','ни','них','но','ну','о','об','однако','он','она','они','оно','от','очень','по','под','при','с','со','так','также','такой','там','те','тем','то','того','тоже','той','только','том','ты','у','уже','хотя','чего','чей','чем','что','чтобы','чье','чья','эта','эти','это','я','a','an','and','are','as','at','be','but','by','for','if','in','into','is','it','no','not','of','on','or','such','that','the','their','then','there','these','they','this','to','was','will','with'],
                    'ignore_case' => true
                ]
            ]
        ],
        'mapping' => [
            'faq_article' => [
                '_source' => [
                    'enabled' => true
                ],
                'properties' => [
                    'id' => [
                        'type' => 'integer'
                    ],
                    'topic' => [
                        'type' => 'integer'
                    ],
                    'question' => [
                        'index_analyzer' => 'app_index_analyzer',
                        'search_analyzer' => 'app_search_analyzer',
                        'type' => 'string'
                    ],
                    'answer' => [
                        'index_analyzer' => 'app_index_analyzer',
                        'search_analyzer' => 'app_search_analyzer',
                        'type' => 'string'
                    ],
                ]
            ]
        ]
    ]
];

```

индексирую документы в цикле

```auto
foreach($articlesFaq as $article){
    $params['id'] = $article->getId();
    $params['body']['id'] = $article->getId();
    $params['body']['topic'] = $article->topic->id;
    $params['body']['question'] = $article->question;
    $params['body']['answer'] = $article->answer;
    try {
        $response = $client->index($params);
        print_r($response);
    } catch (Exception $e) {
        print_r($client->transport->getLastConnection()->getLastRequestInfo());
    }
}

```

но когда я делаю поиск, то я получаю ответы со стоп словами  
по запросу "БЕЗ" мне радостно приходит "КАК ИГРАТЬ БЕЗ"  
по запросу "как" мне приходят "КАК ПОМЕНЯТЬ" и тд

Подскажите, что я сделала не так?

---

<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: [May 23, 2016, 12:16pm UTC](https://discuss.elastic.co/t/topic/50696/2 "2016-05-23T12:16:50Z")

</div>

Давайте начнем с того, что убедимся, что у вас индекс создается правильно. Запустите вот эту команду на сервере Elasticsearch, и давайте сравним установки и схему созданного индекса с установками в Вашем приложении:

```auto
curl localhost:9200/myindex

```

Вы не могли бы также показать, как вы осуществляете поиск?

---

<div class="post-metadata">

### Author: ![dasha](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dasha](https://discuss.elastic.co/u/dasha)
#### Post date: [May 23, 2016, 1:09pm UTC](https://discuss.elastic.co/t/topic/50696/3 "2016-05-23T13:09:50Z")

</div>

```auto
{
  "myindex" : {
    "aliases" : { },
    "mappings" : {
      "faq_article" : {
        "properties" : {
          "answer" : {
            "type" : "string"
          },
          "id" : {
            "type" : "string"
          },
          "mapping" : {
            "properties" : {
              "faq_article" : {
                "properties" : {
                  "_source" : {
                    "properties" : {
                      "enabled" : {
                        "type" : "boolean"
                      }
                    }
                  },
                  "properties" : {
                    "properties" : {
                      "answer" : {
                        "properties" : {
                          "index_analyzer" : {
                            "type" : "string"
                          },
                          "search_analyzer" : {
                            "type" : "string"
                          },
                          "type" : {
                            "type" : "string"
                          }
                        }
                      },
                      "id" : {
                        "properties" : {
                          "type" : {
                            "type" : "string"
                          }
                        }
                      },
                      "question" : {
                        "properties" : {
                          "index_analyzer" : {
                            "type" : "string"
                          },
                          "search_analyzer" : {
                            "type" : "string"
                          },
                          "type" : {
                            "type" : "string"
                          }
                        }
                      },
                      "topic" : {
                        "properties" : {
                          "type" : {
                            "type" : "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "question" : {
            "type" : "string"
          },
          "settings" : {
            "properties" : {
              "analysis" : {
                "properties" : {
                  "analyzer" : {
                    "properties" : {
                      "app_index_analyzer" : {
                        "properties" : {
                          "char_filter" : {
                            "type" : "string"
                          },
                          "filter" : {
                            "type" : "string"
                          },
                          "tokenizer" : {
                            "type" : "string"
                          },
                          "type" : {
                            "type" : "string"
                          }
                        }
                      },
                      "app_search_analyzer" : {
                        "properties" : {
                          "char_filter" : {
                            "type" : "string"
                          },
                          "filter" : {
                            "type" : "string"
                          },
                          "tokenizer" : {
                            "type" : "string"
                          },
                          "type" : {
                            "type" : "string"
                          }
                        }
                      }
                    }
                  },
                  "char_filter" : {
                    "properties" : {
                      "ru" : {
                        "properties" : {
                          "mappings" : {
                            "type" : "string"
                          },
                          "type" : {
                            "type" : "string"
                          }
                        }
                      }
                    }
                  }
                }
              },
              "filter" : {
                "properties" : {
                  "stop" : {
                    "properties" : {
                      "ignore_case" : {
                        "type" : "boolean"
                      },
                      "stopwords" : {
                        "type" : "string"
                      },
                      "type" : {
                        "type" : "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "topic" : {
            "type" : "string"
          }
        }
      }
    },

```

---

<div class="post-metadata">

### Author: ![dasha](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dasha](https://discuss.elastic.co/u/dasha)
#### Post date: [May 23, 2016, 1:10pm UTC](https://discuss.elastic.co/t/topic/50696/4 "2016-05-23T13:10:44Z")

</div>

```auto
"settings" : {
      "index" : {
        "creation_date" : "1463999819039",
        "number_of_shards" : "5",
        "number_of_replicas" : "1",
        "uuid" : "XFsNE63DSB-OSE_L1Xzr0g",
        "version" : {
          "created" : "2030199"
        }
      }
    },
    "warmers" : { }
  }
}

```

---

<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: [May 23, 2016, 1:17pm UTC](https://discuss.elastic.co/t/topic/50696/5 "2016-05-23T13:17:11Z")

</div>

Как я и думал, создание индекса вашей командой не происходит. Индекс, скорее всего, создается автоматически с установками по умолчанию при индексации первой записи. Вам нужно, пересоздать индекс предварительно исправив параметры (`filter` должен быть внутри `analysys` в установках).

---

<div class="post-metadata">

### Author: ![dasha](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dasha](https://discuss.elastic.co/u/dasha)
#### Post date: [May 23, 2016, 3:52pm UTC](https://discuss.elastic.co/t/topic/50696/6 "2016-05-23T15:52:54Z")

</div>

Фильтр исправила. При обращении **curl localhost:9200/myindex** я вижу все по прежнему  
При обращении к конкретному проиндексированному документу **curl localhost:9200/myindex/faq\_article/1**  
выдает вот это

```auto
{
  "_index" : "myindex",
  "_type" : "faq_article",
  "_id" : "1",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "settings" : {
      "analysis" : {
        "char_filter" : {
          "ru" : {
            "type" : "mapping",
            "mappings" : ["Ё=>Е", "ё=>е"]
          }
        },
        "analyzer" : {
          "app_index_analyzer" : {
            "type" : "custom",
            "tokenizer" : "standard",
            "char_filter" : ["ru", "html_strip"],
            "filter" : ["lowercase", "stop", "russian_morphology", "english_morphology"]
          },
          "app_search_analyzer" : {
            "type" : "custom",
            "tokenizer" : "standard",
            "char_filter" : ["ru", "html_strip"],
            "filter" : ["lowercase", "stop", "russian_morphology", "english_morphology"]
          }
        }
      },
      "filter" : {
        "stop" : {
          "type" : "stop",
          "stopwords" : "как,а,без,более,бы,был,была,были,было,быть,в,вам,вас,весь,во,вот,все,всего,всех,вы,где,да,даже,для,до,его,ее,если,есть,еще,же,за,здесь,и,из,или,им,их,к,как,ко,когда,кто,ли,либо,мне,может,мы,на,надо,наш,не,него,нее,нет,ни,них,но,ну,о,об,однако,он,она,они,оно,от,очень,по,под,при,с,со,так,также,такой,там,те,тем,то,того,тоже,той,только,том,ты,у,уже,хотя,чего,чей,чем,что,чтобы,чье,чья,эта,эти,это,я,a,an,and,are,as,at,be,but,by,for,if,in,into,is,it,no,not,of,on,or,such,that,the,their,then,there,these,they,this,to,was,will,with",
          "ignore_case" : true
        }
      }
    },
    "mapping" : {
      "faq_article" : {
        "_source" : {
          "enabled" : true
        },
        "properties" : {
          "id" : {
            "type" : "integer"
          },
          "topic" : {
            "type" : "integer"
          },
          "question" : {
            "index_analyzer" : "app_index_analyzer",
            "search_analyzer" : "app_search_analyzer",
            "type" : "string"
          },
          "answer" : {
            "index_analyzer" : "app_index_analyzer",
            "search_analyzer" : "app_search_analyzer",
            "type" : "string"
          }
        }
      }
    },
    "id" : "1",
    "topic" : "3",
    "question" : "Пополнение лицевого счета",
    "answer" : "<p style=\"box-sizing: border-box; margin: 0px 0px 10px; color: rgb(36, 42, 48); font-family: RobotoRegular, sans-serif; line-height: 18.2px; background-color: rgb(255, 255, 255);\">Какой-то текст</p>\r\n"
  }
}

```

---

<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: [May 23, 2016, 4:01pm UTC](https://discuss.elastic.co/t/topic/50696/7 "2016-05-23T16:01:06Z")

</div>

Судя по результату

```auto
curl localhost:9200/myindex/faq_article/1

```

вы [индексируете](https://github.com/elastic/elasticsearch-php#index-a-document) настройки индекса как документ вместо того, чтобы передавать их как параметр при [создании индекса](https://github.com/elastic/elasticsearch-php#create-an-index). Другими словами, перед индескированием первого документа, надо создать индекс:

```auto
$client->indices()->create($params);

```

После этого params надо почистить - в каждом документе они больше не нужны.

---

<div class="post-metadata">

### Author: ![dasha](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dasha](https://discuss.elastic.co/u/dasha)
#### Post date: [May 23, 2016, 4:46pm UTC](https://discuss.elastic.co/t/topic/50696/8 "2016-05-23T16:46:35Z")

</div>

Создала индекс через **$client-\>indices()-\>create($params)**

```auto
[index] => myindex
    [type] => faq_article
    [id] => 24
    [body] => Array
        (
            [id] => 24
            [topic] => 1
            [question] => как играть без аккаунта?
            [answer] => <span style="color: rgb(36, 42, 48); font-family: RobotoRegular, sans-serif; line-height: 18.2px; background-color: rgb(255, 255, 255);">/*....*/</span>
        )

```

проиндексировала документы через **$client-\>index($docs)**

но когда делаю поиск

```auto
 $params = [
		'index' => 'myindex',
		'type' => 'faq_article',
		'body' => [
		'query'=> array(
		'function_score'=> array(

			'query'=> array(
				'multi_match'=> array(
					'query'=> $search,
					'operator'=> 'OR',
					'fields'=> array(
						'question',
						'answer'
					)
				)
			),                     
			'functions'=> array(
			),
			'boost_mode'=> 'multiply'
		)
	)
];

$response = $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: [May 23, 2016, 5:49pm UTC](https://discuss.elastic.co/t/topic/50696/9 "2016-05-23T17:49:39Z")

</div>

А что возвращают теперь эти две команды?

```auto
curl localhost:9200/myindex/

```

```auto
curl localhost:9200/myindex/faq_article/24

```

---

<div class="post-metadata">

### Author: ![dasha](https://avatars.discourse-cdn.com/v4/letter/d/898d66/32.png) [@dasha](https://discuss.elastic.co/u/dasha)
#### Post date: [May 24, 2016, 7:52am UTC](https://discuss.elastic.co/t/topic/50696/10 "2016-05-24T07:52:44Z")

</div>

> [@Igor\_Motov](#):
>
> /faq\_article/24

curl localhost:9200/myindex/ возвращает

```auto
{
  "myindex" : {
    "aliases" : { },
    "mappings" : {
      "faq_article" : {
        "properties" : {
          "answer" : {
            "type" : "string"
          },
          "id" : {
            "type" : "string"
          },
          "question" : {
            "type" : "string"
          },
          "topic" : {
            "type" : "string"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "filter" : {
          "stop" : {
            "ignore_case" : "true",
            "type" : "stop",
            "stopwords" : ["как", "а", "без", "более", "бы", "был", "была", "были", "было", "быть", "в", "вам", "вас", "весь", "во", "вот", "все", "всего", "всех", "вы", "где", "да", "даже", "для", "до", "его", "ее", "если", "есть", "еще", "же", "за", "здесь", "и", "из", "или", "им", "их", "к", "как", "ко", "когда", "кто", "ли", "либо", "мне", "может", "мы", "на", "надо", "наш", "не", "него", "нее", "нет", "ни", "них", "но", "ну", "о", "об", "однако", "он", "она", "они", "оно", "от", "очень", "по", "под", "при", "с", "со", "так", "также", "такой", "там", "те", "тем", "то", "того", "тоже", "той", "только", "том", "ты", "у", "уже", "хотя", "чего", "чей", "чем", "что", "чтобы", "чье", "чья", "эта", "эти", "это", "я", "a", "an", "and", "are", "as", "at", "be", "but", "by", "for", "if", "in", "into", "is", "it", "no", "not", "of", "on", "or", "such", "that", "the", "their", "then", "there", "these", "they", "this", "to", "was", "will", "with"]
          }
        },
        "number_of_shards" : "5",
        "creation_date" : "1464023773416",
        "analysis" : {
          "analyzer" : {
            "app_search_analyzer" : {
              "filter" : ["lowercase", "stop", "russian_morphology", "english_morphology"],
              "char_filter" : ["ru", "html_strip"],
              "type" : "custom",
              "tokenizer" : "standard"
            },
            "app_index_analyzer" : {
              "filter" : ["lowercase", "stop", "russian_morphology", "english_morphology"],
              "char_filter" : ["ru", "html_strip"],
              "type" : "custom",
              "tokenizer" : "standard"
            }
          },
          "char_filter" : {
            "ru" : {
              "type" : "mapping",
              "mappings" : ["Ё=>Е", "ё=>е"]
            }
          }
        },
        "number_of_replicas" : "1",
        "uuid" : "zv7NIpnvSHyM5NaYxY6aOA",
        "version" : {
          "created" : "2030199"
        }
      }
    },
    "warmers" : { }
  }
}

```

curl localhost:9200/myindex/faq\_article/24 возвращает

```auto
{
  "_index" : "myindex",
  "_type" : "faq_article",
  "_id" : "24",
  "_version" : 1,
  "found" : true,
  "_source" : {
    "id" : "24",
    "topic" : "1",
    "question" : "ЧТО ЗА МОД ИГРЫ?",
    "answer" : "<span style="color: rgb(36, 42, 48); font-family: RobotoRegular, sans-serif; line-height: 18.2px; background-color: rgb(255, 255, 255);">/*...*/</span>"
  }
}

```

---

<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: [May 24, 2016, 12:59pm UTC](https://discuss.elastic.co/t/topic/50696/11 "2016-05-24T12:59:03Z")

</div>

Ну, по крайней мере, мы движемся в правильном направлении - установки индекса в индексе появились. Теперь надо маппингом исправить. Я, думаю, проблема тут

```auto
        'mapping' => [
            'faq_article' => [
                '_source' => [

```

должно быть `'mappings' => ....`

---

<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: [July 6, 2017, 1:48pm UTC](https://discuss.elastic.co/t/topic/50696/12 "2017-07-06T13:48:11Z")

</div>


