# Search text part in object

**URL:** https://discuss.elastic.co/t/search-text-part-in-object/293332
**Category:** Elasticsearch
**Created:** [January 3, 2022, 9:39am UTC](https://discuss.elastic.co/t/search-text-part-in-object/293332 "2022-01-03T09:39:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![MrDeliK](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MrDeliK](https://discuss.elastic.co/u/MrDeliK)
#### Post date: [January 3, 2022, 9:39am UTC](https://discuss.elastic.co/t/search-text-part-in-object/293332/1 "2022-01-03T09:39:35Z")

</div>

Hi guys, new here and had some trouble for this basic search.  
In the database, we have objects containing strings like this.

```auto
{fr: "french string", en: "english string", nl: "nl string"}

```

for generic purpose (defined in the project) i need to avoid creating precise mapping.

I need to be able to search text part but as a single string.  
For example, the string `english s` is not consider as a single string.

I tried a lot of things and none works for now.

Does anyone know how this could work ?  
Thanks 🙂

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 3, 2022, 9:55am UTC](https://discuss.elastic.co/t/search-text-part-in-object/293332/2 "2022-01-03T09:55:18Z")

</div>

Welcome!

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script is something anyone can **copy and paste in Kibana dev console** , click on the run button to reproduce your use case. It will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

### Author: ![MrDeliK](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MrDeliK](https://discuss.elastic.co/u/MrDeliK)
#### Post date: [January 3, 2022, 1:08pm UTC](https://discuss.elastic.co/t/search-text-part-in-object/293332/3 "2022-01-03T13:08:29Z")

</div>

Thanks for your reply.  
Unfortunately i'm not involved in the all process but i can provide an example of the datas i try to fetch  
As i said earlier we have that object containing string.

```auto
{
  "sample_data": {
    "mappings": {
      "properties": {
        "$id": {
          "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
        },
        "title": {
           "properties": {
              "fr": {
                 "type": "text",
                 "fields": {
                     "keyword": {
                      "type": "keyword",
                          "ignore_above": 256
                        }
                      }
                   },
                  "nl": {
                      "type": "text",
                      "fields": {
                          "keyword": {
                              "type": "keyword",
                               "ignore_above": 256
                            }
                        }
                   },
                   "poly": {
                     "type": "text",
                     "fields": {
                       "keyword": {
                         "type": "keyword",
                           "ignore_above": 256
                         }
                       }
                     }
                   }
          },
      }
    }
  }
}

```

For example those datas

```auto
[
  {
  "_index": "sample_data",
  "_type": "_doc",
  "_id": "elem0",
  "_version": 1,
  "_score": 1.0,
  "_source": {
    "$id": "elem0"
    "title": {
      "fr": "test with fr",
      "nl": "test with nl"
    },
  },
  {
  "_index": "sample_data",
  "_type": "_doc",
  "_id": "elem1",
  "_version": 1,
  "_score": 1.0,
  "_source": {
    "$id": "elem1"
    "title": {
      "fr": "test 2 with fr",
      "nl": "test 2 with nl"
    },
  },
]

```

I tried various request but none works for what i want.  
If I search with the string `test with` i will have everything in the response but i only want the `test with fr` element (`elem0`) to be returned because the `2` is not in my request.

```auto
{
  "query": {
    "query_string": {
        "query": "*test with*"
    }
   }
}

```

same problem if the query contain non finished word

```auto
{
  "query": {
    "query_string": {
        "query": "*test wi*"
    }
   }
}

```

---

<div class="post-metadata">

### Author: ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)
#### Post date: [January 3, 2022, 3:19pm UTC](https://discuss.elastic.co/t/search-text-part-in-object/293332/4 "2022-01-03T15:19:42Z")

</div>

Hi,  
I suppose you may use match phrase query or wildcard query with wildcard field. Is there any reason to use query\_string query? If then, how about the query below?

```auto
{
  "query": {
    "query_string": {
        "query": "\"test with\""
    }
  }
}

```

Query\_string query is a text type query. Query ("text with") will be analyzed into terms (e.g. ["text", "with"]). You can use a phrase, surrounded by double quotes, while the result depends on the analyzer.

> **[Query string query | Elasticsearch Guide \[7.16\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax)**

---

<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, 3:20pm UTC](https://discuss.elastic.co/t/search-text-part-in-object/293332/5 "2022-01-31T15:20:02Z")

</div>

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