Filter Then Sort Results By Query in ElasticSearch

Ian

Is there a way in ElasticSearch to run a boolean filter, then without refinding the search further, sort/order the results based on a multi_field query?

Eg: Get all items with status_id = 1 (the filter), then order those documents by using the keywords "red car" (documents whose name and description contain those keywords are first, documents without are last).

Vineeth Mohan

You can use bool query - As per condition of should -

The clause (query) should appear in the matching document. In a boolean query with no must clauses, one or more should clauses must match a document. The minimum number of should clauses to match can be set using the minimum_should_match parameter.

In our case , as there is a must and its a number match , score value wont be computed. But then conditions in should would be used for computing the score alone -

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "status_id": 1
          }
        }
      ],
      "should": [
        {
          "multi_match": {
            "query": "red car",
            "fields": [
              "subject",
              "message"
            ]
          }
        }
      ]
    }
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Elasticsearch bool filter query return results

From Dev

Elasticsearch 2.x, query for tag, and sort results by tag weigth

From Dev

Elasticsearch 2.x, query for tag, and sort results by tag weigth

From Dev

ElasticSearch: getting facets from all results with filter query

From Dev

Elasticsearch query yeilds no results

From Dev

Are ElasticSearch query results cached?

From Dev

Parameter to filter query results

From Dev

filter over query results

From Dev

ElasticSearch nested query with filter

From Dev

Elasticsearch arrays query/filter

From Dev

elasticsearch filter query not work

From Dev

Elasticsearch bool query with filter

From Dev

Elasticsearch: Filter Query not working

From Dev

Elasticsearch Filter Query

From Dev

Elasticsearch filter results excluding by id

From Dev

Elasticsearch terms filter returns no results

From Dev

Elasticsearch terms filter returns no results

From Dev

How and where filter and sort query results using symfony 2.4 ( according to MCV )

From Dev

Can I filter query results in DynamoDB with ComparisonOperator.IN on the sort key of my local secondary index?

From Dev

Elasticsearch Geoshape query false results

From Dev

ElasticSearch sort query alphabetically with score

From Dev

Filter SQL query results by aggregrate

From Dev

Elasticsearch Query Filter for Word Count

From Dev

Elasticsearch: Filter (or Query) by Term Frequency

From Dev

How to wrap an ElasticSearch filter in a query

From Dev

Elasticsearch Filtered query vs Filter

From Dev

How to wrap an ElasticSearch filter in a query

From Dev

ElasticSearch conditional filter query by type

From Dev

Elasticsearch Query Filter for Word Count

Related Related

HotTag

Archive