Search code examples
elasticsearchelasticsearch-percolate

Is there a way to bulk-add ElasticSearch percolations?


I want to throw my many documents to a LOT of percolator queries (my query count is in the 6-digit). I've found how to multi-percolate many documents at once, but haven't found how to bulk-add many queries at once.

According to the documentation, I can register a query in the percolator using:

curl -XPUT 'localhost:9200/my-index/.percolator/1' -d '{
    "query" : {
        "match" : {
            "message" : "bonsai tree"
        }
    }
}'

Can I add many of these in one fell swoop?


Solution

  • Since queries are indexed like normal documents would, you could simply bulk-add them like this:

    curl -s -XPOST localhost:9200/_bulk -d '
    { "index" : { "_index" : "my-index", "_type" : ".percolator", "_id" : "1" } }
    { "query" : { "match" : { "message" : "bonsai tree" } }}
    { "index" : { "_index" : "my-index", "_type" : ".percolator", "_id" : "2" } }
    { "query" : { "match" : { "message" : "abc" } }}
    { "index" : { "_index" : "my-index", "_type" : ".percolator", "_id" : "3" } }
    { "query" : { "match" : { "message" : "def" } }}
    { "index" : { "_index" : "my-index", "_type" : ".percolator", "_id" : "4" } }
    { "query" : { "match" : { "message" : "xyz" } }}
    '