Google-like search behaviors : wildcards, exact match

Hello,
I'm trying to add some well-known behaviors on my search engine, so users can use what they already know with Google search engine : double quotes for exact matchs, wildcards...

From what I've seen, a query_string request seems ideal because it is already parsing the string to find all those things, which is great news, but the exact match behavior is different from Google and I don't really understand why.

I'm playing around with Kibana so far, but I'm using the php driver and ES 6.5. Here's a request example :

{
  "size": 20,
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "Foo \"exact match string\" Bar",
            "fields" : [
               "field1",
               "field2^2"
              ]
          }
        }
      ]
    }
  }
}

The issue here is with the words Foo and Bar, because the results still give me documents without my "exact match string". From what I've observed, it is because they contain either Foo or Bar, which is not how Google work. "exact match string" should always be in the searched fields, whether Foo or Bar is found.
If my query is only "exact match string", it seems to work well and only gives me results containing the string.

Keep in mind this is only a sample request, my final request also includes searching in nested fields, and has aggregations, if that matters at all. This is why there's a "should" instruction, I need to search in nested1, nested2, and a query_string in some fields, but I don't think it's a problem to achieve what I want.

Am I missing something here ?

You might try something:

"Foo +\"exact match string\" Bar"

Or change default_operator which is OR by default to AND.

My 2 cents

1 Like

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