How to restrict documents to only include the wildcard search phrase?

I want to do a wild card search below to return results that only include the phrase "joe smith". This works but it also includes records without his name. I've played with the "min_score" value to help on this but I want something to be more precise. If it doesn't include the phrase don't include it in the result.
Or is my query approach incorrect?

GET my_index/_search
{
  "query": {
    "query_string": {
      "query": "*\"joe smith\"*",
      "fields": ["*"],
      "analyze_wildcard": true
    }
  },
  "size": 8000,
 "min_score" : 2
}

Hi @dev8100
Have you try Match phrase query | Elasticsearch Guide [8.15] | Elastic

?

1 Like

Thanks. I tried it

GET /_search
{
  "query": {
    "match_phrase": {
      "message": "joe smith"
    }
  }
}

and it returned 0 results.

  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  }

Is "message" supposed to be field in one of our indexes or is it a generic value that will be searched across all indexes? I'm unclear on that. We'd like to search all fields as of now.

Can you share how is your mapping looks like using mapping query -

GET my-index/_mapping

We want to search across all indexes so each mapping is different

To understand this, we need to see how data has been indexed across the indexes. For that we need to know the mapping. Or if you can share some sample data with index query and what you're looking for. We can do quick poc.

The mapping of the fields searched will impact what results a particular query returns. If you index the same string in a field mapped as a keyword and a different fields that is analyzed a specific query may find only one, both or maybe even none of them.