2

I have a document with multiple fields such as

"identifier" ( string ) analyzed

"description" ( string ) analyzed

"remark" ( string ) analyzed

of course the general scoring based queries work very well.

E.g. if I search for blue car it shows relevant results with the right scoring algorithm etc.

Although I have the requirement to implement a google like exact match query as well

E.g. "blue car" should only return documents where the exact phrase "blue car" appears anywhere in the text in any of the fields.

What is the best way to implement this ?

Thanks a lot !

0

1 Answer 1

3

Try this, meaning a multi_match with phrase type:

{
  "query": {
    "multi_match": {
      "query": "blue car",
      "fields": [
        "text",
        "message",
        "whatever"
      ],
      "type": "phrase"
    }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

I have tried queries and I do not believe it is as simple as that. thanks a lot
I think this will not work for the exact match. Type "phrase" does a "match_phrase" which doesn't check the exact string. (Ref: stackoverflow.com/questions/26001002/…). Instead, it checks if all the words of query are present in the same order.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.