0
s = Search(index='test-index').using(client)
q = Q('percolate',
            field="query",
            documents=list_of_documents)
s = s.query(q)
p = s.execute()

I am attempting to run a percolation query against an index, with a list of documents and I am getting the error

RequestError(400, 'search_phase_execution_exception', 'Field [_id] is a metadata field and cannot be added inside a document. Use the index API request parameters.').

Any help solving this is very much appreciated.

Kevin Quinzel
  • 1,430
  • 1
  • 13
  • 23
Justin Reddick
  • 441
  • 1
  • 5
  • 20

1 Answers1

0

I'll start to explain this via the APIs.

The Percolate query can be used to match queries stored in an index.

When creating an index with a Percolate field, you specify a mapping like this:

PUT /my-index
{
    "mappings": {
         "properties": {
             "message": {
                 "type": "text"
             },
             "query": {
                 "type": "percolator"
             }
        }
    }
}

This indicates that the field message will be the one used for the Percolate query.

If you would like to match a list of documents, a list of terms with this field should be sent like in the example found in the docs:

GET /my-index/_search
{
    "query" : {
        "percolate" : {
            "field" : "query",
            "documents" : [ 
                {
                    "message" : "bonsai tree"
                },
                {
                    "message" : "new tree"
                },
                {
                    "message" : "the office"
                },
                {
                    "message" : "office tree"
                }
            ]
        }
    }
}

Said this, you should:

  1. Set the proper mappings in your ES index to Percolate a specific field.

  2. In the DSL, send the list of parameters only with the "Percolated" field, instead of the whole ES document.

Hope this is helpful :D

Kevin Quinzel
  • 1,430
  • 1
  • 13
  • 23
  • 1
    I am able to do this with the ES API no problem, but the issue is recreating this exact function but using the Python `elasticsearch-dsl` library. – Justin Reddick Feb 11 '20 at 17:47