mrdgan
mrdgan

Reputation: 1

How to limit the results in a multi match query?

i had used multi match phrase when I make search. However I have to put limit result of all math phrase seperately. I mean, I want to take only 2 result for each multi match. I can't find any limit/size attributes. Do you know any solution?

Example Code:

  "query": {
"bool": {
  "should": [
     {
      "match_phrase": {
        "text": {
          "query": " Home is clear and big ",
          "slop": 2

    }
 }
 },
  {
  "match_phrase": {
    "text": {
      "query": "365 different company use our system in test",
      "slop": 2

    }
 }
 }

]}}

Upvotes: 0

Views: 1909

Answers (2)

Alexandru R
Alexandru R

Reputation: 8823

use

{"limit" : 3, "from":0, "query": ...} 

Upvotes: 1

The simplest solution is to make to individual searches for each of the conditions. The size parameter can be set to retrieve only the first 2 results for each query.

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html

The boolean should query will not distinguish which condition has been satisfied: it returns documents for which at least one of the two conditions holds. The scores for the two matches will be combined into a single score but it will be impossible to tell which s

Upvotes: 0

Related Questions