# Поиск через should и wildcard

**URL:** <https://discuss.elastic.co/t/should-wildcard/164125>\
**Category:** Вопросы на русском языке\
**Created:** [January 14, 2019, 10:32am UTC](https://discuss.elastic.co/t/should-wildcard/164125 "2019-01-14T10:32:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mykola\_Vantukh](https://avatars.discourse-cdn.com/v4/letter/m/ed8c4c/32.png) [@Mykola\_Vantukh](https://discuss.elastic.co/u/Mykola_Vantukh)\
**Post date:** [January 14, 2019, 10:32am UTC](https://discuss.elastic.co/t/should-wildcard/164125/1 "2019-01-14T10:32:00Z")

</div>

всем привет . нужна ваша помощь  
пытаюсь искать через wildcard и should , но оно работает как-то странно .

```
                         'bool' => [
 "should" => [
                                    [
                                        "wildcard" => ["product_name.letter" => "*" . $this->formatQueryStr($query) . "*"]
                                    ],
                                    [
                                        "wildcard" => ["product_name.digit" => "*" . $this->formatQueryStr($query) . "*"]
                                    ]
                                ],
                            ],

```

маппинг

```
'settings' => [
                    "analysis" => [
                        "analyzer" => [
                            "letter_analyzer" => [
                                "type" => "custom",
                                "tokenizer" => 'letter_tokenizer',
                                "filter" => [
                                    "lowercase"
                                ]
                            ],
                            "digit_analyzer" => [
                                "type" => "custom",
                                "tokenizer" => 'digit_tokenizer'
                            ],
                        

                        ],
                        "tokenizer" => [
                            'letter_tokenizer' => [
                                "type" => "char_group",
                                "tokenize_on_chars" => [
                                    "whitespace",
                                    "punctuation",
                                    "symbol",
                                    "digit"
                                ]
                            ],
                            'digit_tokenizer' => [
                                "type" => "char_group",
                                "tokenize_on_chars" => [
                                    "whitespace",
                                    "punctuation",
                                    "symbol",
                                    "letter"
                                ]
                            ],
                          
                        ],

                    ]
                ],
                'mappings' => [
                    'product' => [
                        'properties' => [
                            'id' => [
                                'type' => 'integer'
                            ],
                            'model' => [
                                'type' => 'text'
                            ],
                            'image' => [
                                'type' => 'text'
                            ],
                            'product_name' => [
                                'type' => 'text',
                                "analyzer" => "keyword",
                                "fields" => [
                                    "letter" => [
                                        "type" => "text",
                                        "analyzer" => "letter_analyzer",
                                    ],
                                    "digit" => [
                                        "type" => "text",
                                        "analyzer" => "digit_analyzer",
                                    ],
                                   
                                ],
                            ]
                        ]
                    ]
                ]

```

как я понимаю оно должно пробегатся по токенам и искать по ним фразу нужную .вот например есть 4Good T700i и токены [4,Good,T,700,i] если я ищу good ,то все ок находит , но если написать 4good то ничего нет , хотя по логике оно должно найти "4" через второй wildcard и good через первый . или я что-то неправильно понимаю?

---

<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:** [January 14, 2019, 6:40pm UTC](https://discuss.elastic.co/t/should-wildcard/164125/2 "2019-01-14T18:40:19Z")

</div>

`wildcard` не анализирует запросы. Поэтому `4Good` будет искать токены в которых содержиться `4Good`, у вас такого токена нет. В целом, то что вы делаете будет работать крайне неоптимально. Вы не могли бы рассказать, что вы пытаетесь добиться?

---

<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:** [February 11, 2019, 6:42pm UTC](https://discuss.elastic.co/t/should-wildcard/164125/3 "2019-02-11T18:42:15Z")

</div>

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