Search text part in object

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

{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 :slight_smile:

Welcome!

Could you provide a full recreation script as described in About the Elasticsearch category. 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.

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.

{
  "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

[
  {
  "_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.

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

same problem if the query contain non finished word

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

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?

{
  "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.

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