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 !

Istvano
  • 992
  • 1
  • 12
  • 19

1 Answers1

3

Try this, meaning a multi_match with phrase type:

{
  "query": {
    "multi_match": {
      "query": "blue car",
      "fields": [
        "text",
        "message",
        "whatever"
      ],
      "type": "phrase"
    }
  }
}
Andrei Stefan
  • 51,654
  • 6
  • 98
  • 89
  • I have tried queries and I do not believe it is as simple as that. thanks a lot – Istvano Jan 19 '15 at 16:29
  • I think this will not work for the exact match. Type "phrase" does a "match_phrase" which doesn't check the exact string. (Ref: https://stackoverflow.com/questions/26001002/elastic-search-difference-between-term-match-phrase-and-query-string). Instead, it checks if all the words of query are present in the same order. – Ankit Bhatia Oct 01 '18 at 11:39