Elasticsearch: Using filter with elasticsearch 5.1 Percolate

Created on 9 Feb 2017  路  4Comments  路  Source: elastic/elasticsearch

Elasticsearch version: 5.1

Plugins installed: Head

JVM version: 1.8

OS version:Ubuntu- 14.04

Steps to reproduce:

  1. I created one field with type percolator [field name query] in index A.
  2. I used below mentioned query using curl POST
http://localhost:9200/A/type/_search POST
{
  "query": {
    "percolate": {
      "field": "query",
      "document_type": "b",
      "type": "b",
      "id": 51411883, // id of the document for which matching queries needed from Index A
      "index": "B"
    },
// below is the filter i am trying to add but not working Error: [percolate] malformed query, expected // [END_OBJECT] but found [FIELD_NAME]
// is there a different way to use filter with percolate query.
// Also did not find any help from Elastic docs regarding same.

    "bool": {
      "filter": {
        "terms": {
          "is_leap_prf": 1
        }
      }
    }
  }
}

Most helpful comment

The percolate query should work like any other query, ie.

http://localhost:9200/A/type/_search POST
{
  "query": {
    "bool": {
      "must": [
        {
          "percolate": {
            "field": "query",
            "document_type": "b",
            "type": "b",
            "id": 51411883,
            "index": "B"
          }
        }
      ],
      "filter": [
        {
          "terms": {
            "is_leap_prf": 1
          }
        }
      ]
    }
  }
}

All 4 comments

A post filter can be used

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

But this only has one filter that can be added.

The percolate query should work like any other query, ie.

http://localhost:9200/A/type/_search POST
{
  "query": {
    "bool": {
      "must": [
        {
          "percolate": {
            "field": "query",
            "document_type": "b",
            "type": "b",
            "id": 51411883,
            "index": "B"
          }
        }
      ],
      "filter": [
        {
          "terms": {
            "is_leap_prf": 1
          }
        }
      ]
    }
  }
}

I'm closing as I assume this would fix your issue. Please reopen if it does not.

Thank you @priyolahiri and @jpountz . This resolved my issue.

Was this page helpful?
0 / 5 - 0 ratings