jpganz18
jpganz18

Reputation: 5858

how to properly use wildcard on a elastic search find?

I just jumped into ES and I dont have a lot of experience on this, so might be something I am missing on this.

I found this documentation: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html that basically explains how to do a wildcard search.

I am trying to look for all messages inside my document that have certain patter.

So, using Kibana Sense (Elastic search query UI)I did this:

GET _search
{
    "query": {
        "wildcard" : {
            "model.message": "my*"
        }
    }
}

with this I am trying to obtain all the messages that start with "my"

But I get no results...

Here is a copy of my document structure (or at least the first lines...)

 "_index": "my_index",
    "_type": "my_type",
    "_id": "123456",
    "_source": {
      "model": {
        "id": "123456",
        "message": "my message",

Any idea what could be wrong?

Upvotes: 1

Views: 4479

Answers (2)

Val
Val

Reputation: 217274

Your sample document actually contains the model.content.message field but not the model.message field, so the following query should work:

GET _search
{
    "query": {
        "wildcard" : {
            "model.content.message": "my*"
        }
    }
}

Upvotes: 3

hudsonb
hudsonb

Reputation: 2294

Can you share your mapping? It looks like you need to use a nested query:

GET /_search
{
    "query": {
        "nested" : {
            "path" : "model",
            "score_mode" : "avg",
            "query" : {
                "wildcard" : {
                    "model.message": "my*"
                }
            }
        }
    }
}

You can read more about nested queries here.

Upvotes: 0

Related Questions