# Search for parts of a string field

**URL:** <https://discuss.elastic.co/t/search-for-parts-of-a-string-field/219670>\
**Category:** Elasticsearch\
**Created:** [February 17, 2020, 6:48pm UTC](https://discuss.elastic.co/t/search-for-parts-of-a-string-field/219670 "2020-02-17T18:48:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabriciofs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fabriciofs/32/62839_2.png) [@fabriciofs](https://discuss.elastic.co/u/fabriciofs)\
**Post date:** [February 17, 2020, 6:48pm UTC](https://discuss.elastic.co/t/search-for-parts-of-a-string-field/219670/1 "2020-02-17T18:48:37Z")

</div>

Hello guys, I'm new to the Elasticsearch world and I'm sorry if my doubt is very basic.  
I need to create an index on there will be a type that will store a product catalog. In this there will be several fields but what I need to use for research is only one DESCRIPTION field.

Examples of contents in the DESCRIPTION field:  
CH COMBINADA 06MM GEDORE  
CH COMBINADA 07MM GEDORE  
CH COMBINADA 08MM GEDORE  
CH COMBINADA 06MM BESEL  
CH COMBINADA 07MM BESEL  
CH COMBINADA 08MM BESEL

An example of a search would be "CH COMB 06"

records should be returned:  
CH COMBINADA 06MM GEDORE  
CH COMBINADA 06MM BESEL

but nothing returns. I've used several techniques I found on google but nothing works.

if I search for "CH COMBINADA", it returns results, but I really need to search for one or more parts of words.

In other words, you need the LIKE operator of the SQL language.

Can someone give me a light?

---

<div class="post-metadata">

**Author:** ![abdelhedi\_yassine](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@abdelhedi\_yassine](https://discuss.elastic.co/u/abdelhedi_yassine)\
**Post date:** [February 17, 2020, 7:23pm UTC](https://discuss.elastic.co/t/search-for-parts-of-a-string-field/219670/2 "2020-02-17T19:23:11Z")

</div>

Hi Fabricio,

you can use a wild card query: `"CH COMB*06*"`  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html)

---

<div class="post-metadata">

**Author:** ![fabriciofs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fabriciofs/32/62839_2.png) [@fabriciofs](https://discuss.elastic.co/u/fabriciofs)\
**Post date:** [February 17, 2020, 8:55pm UTC](https://discuss.elastic.co/t/search-for-parts-of-a-string-field/219670/3 "2020-02-17T20:55:48Z")

</div>

Hello, thanks for the quick response.  
I had already tried with the link instruction that you passed. However I was not successful. For example:  
I have a product that the description is: "ARMARIO P/FERRAMENTA AM-2 / MARCON".

If I use the query as written below, it returns results:  
`{ "query": { "wildcard": { "descricao": { "value": "arma*" } } } }`  
However, with the other methods below, nothing returns  
`{ "query": { "wildcard": { "descricao": { "value": "arma*ferra*" } } } }`  
`{ "query": { "wildcard": { "descricao": { "value": "ARMA* FERRA*" } } } }`  
`{ "query": { "wildcard": { "descricao": { "value": "arma* *ferra*" } } } }`  
`{ "query": { "wildcard": { "descricao": { "value": "ARMA* FERRAMENTA*" } } } }`

If I use 2 terms or more, it does not return results.

---

<div class="post-metadata">

**Author:** ![abdelhedi\_yassine](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@abdelhedi\_yassine](https://discuss.elastic.co/u/abdelhedi_yassine)\
**Post date:** [February 18, 2020, 2:25am UTC](https://discuss.elastic.co/t/search-for-parts-of-a-string-field/219670/4 "2020-02-18T02:25:52Z")

</div>

you can use 2 x must much :

```
  "query": {
        "bool": {
           "must": [
               {"match": {"descricao": "arma"}},
               {"match": {"descricao":"ferra"}}
            ]
         }
    }
```

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [February 18, 2020, 8:22am UTC](https://discuss.elastic.co/t/search-for-parts-of-a-string-field/219670/5 "2020-02-18T08:22:25Z")

</div>

See this [topic](https://discuss.elastic.co/t/regex-with-query-from-string/218312/2) about double wildcards

---

<div class="post-metadata">

**Author:** ![fabriciofs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fabriciofs/32/62839_2.png) [@fabriciofs](https://discuss.elastic.co/u/fabriciofs)\
**Post date:** [February 18, 2020, 11:58am UTC](https://discuss.elastic.co/t/search-for-parts-of-a-string-field/219670/6 "2020-02-18T11:58:32Z")

</div>

Using wildcard I got a result very close to what I need. But now I have another problem.

For example, in my SQL database, if I send the following query  
(`SELECT * FROM produtos WHERE descricao LIKE 'PF%SX%1/2%'`) I get the following result:  
`PF SX D 3/16X1/2 RI BSW-24 G2 PO`  
`PF SX D 3/16X 1.1/2 RI BSW-24 G2 PO`  
`PF SX D 3/16X 2.1/2 RI BSW-24 G2 PO`  
`PF SX F 1/4X 1/2 RI UNC-20 G2 PO`  
`PF SX F 1/4X 1.1/2 RI UNC-20 G2 PO`  
`PF SX F 1/4X 2.1/2 RI UNC-20 G2 PO`  
`PF SX F 1/4X 4.1/2 RI UNC-20 G2 PO`  
`PF SX F 1/4X 5.1/2 RI UNC-20 G2 PO`  
`PF SX G 5/16X 1/2 RI UNC-18 G2 PO`

In elastic, if I search the way below, no results will return.  
`{`  
` "query": {`  
` "bool": {`  
` "must": [`  
` {"wildcard": {"descricao": "pf"}},`  
` {"wildcard": {"descricao": "sx*"}},`  
` {"wildcard": {"descricao": "1/2*"}}`  
` ]`  
` }`  
` }`  
`}`

I believe the problem is the term `1/2`. Because if I remove the condition `{"wildcard": {"description": "1/2 *"}` returns results.

Is there any way to use slashes on the filters?

---

<div class="post-metadata">

**Author:** ![abdelhedi\_yassine](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@abdelhedi\_yassine](https://discuss.elastic.co/u/abdelhedi_yassine)\
**Post date:** [February 18, 2020, 1:42pm UTC](https://discuss.elastic.co/t/search-for-parts-of-a-string-field/219670/7 "2020-02-18T13:42:16Z")

</div>

You will need to change the mapping of the field to not be analyzed, otherwise the slashes will not be indexed.  
you can check these 2 posts on how to use slashes in filters:

[https://discuss.elastic.co/t/how-to-use-slash-to-search-in-discovery/92340](https://discuss.elastic.co/t/how-to-use-slash-to-search-in-discovery/92340)

> <https://stackoverflow.com/questions/44981143/how-to-use-slash-in-kibana-discovery>

---

<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:** [March 17, 2020, 1:42pm UTC](https://discuss.elastic.co/t/search-for-parts-of-a-string-field/219670/8 "2020-03-17T13:42:24Z")

</div>

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