{"id":22152148,"url":"https://github.com/findinpath/elastic-percolate-query-searcher","last_synced_at":"2026-05-06T07:37:37.185Z","repository":{"id":112790913,"uuid":"277542371","full_name":"findinpath/elastic-percolate-query-searcher","owner":"findinpath","description":"Proof of concept on how to parse a JSON query to a Elastic QueryBuilder","archived":false,"fork":false,"pushed_at":"2020-07-06T13:09:34.000Z","size":62,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-29T18:32:10.781Z","etag":null,"topics":["elasticsearch","percolator","search"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/findinpath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-06T12:58:40.000Z","updated_at":"2020-07-06T13:09:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"b1901fb5-101f-4f5e-b7af-485d991fc153","html_url":"https://github.com/findinpath/elastic-percolate-query-searcher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findinpath%2Felastic-percolate-query-searcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findinpath%2Felastic-percolate-query-searcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findinpath%2Felastic-percolate-query-searcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/findinpath%2Felastic-percolate-query-searcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/findinpath","download_url":"https://codeload.github.com/findinpath/elastic-percolate-query-searcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245277467,"owners_count":20589154,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elasticsearch","percolator","search"],"created_at":"2024-12-02T00:47:25.777Z","updated_at":"2026-05-06T07:37:37.131Z","avatar_url":"https://github.com/findinpath.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Elastic Percolator Query Searcher\n=================================\n\nA common use case in working with Elasticsearch are the so called _\"search alerts\"_\nwhich can be used (as [Google Alerts](https://www.google.com/alerts) puts it) to:\n\n\u003e Monitor the web for interesting new content\n\n\nA [percolate](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-percolate-query.html) \nquery can be executed to find out which registered search queries match the specified document \nfor the query.\n\nThis functionality can be useful in case of dealing with alerts which require immediate\nnotification. For each queried document/ batch of documents, there will be issued one\nnotification for the matching registered search queries.\n\nAssuming that the notifications for the search alerts should be batched so that the user gets notified\nonly after a certain time window (e.g.: hour, day, week) elapses \n(in case that the search alert matches at least one from the indexed documents during the time window), \nthere should be retrieved the JSON search query corresponding to the alert and execute it against \nthe search index so that the latest documents matching the search query to be retrieved and used in\nthe body of the user notification.\n\nIt takes quite some time to find on the Internet how to convert a JSON query in a\n`org.elasticsearch.index.query.QueryBuilder` so that it can be used in a \n`org.elasticsearch.action.search.SearchRequest`.\nThis simple project deals exactly with this problem.\n\nConverting a JSON query to a `org.elasticsearch.index.query.QueryBuilder`\ncan be done in the same fashion as in the \n[BoolQueryBuilderTests.java](https://github.com/elastic/elasticsearch/blob/master/server/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java#L222).\n\nBy looking after the string [testFromJson()](https://github.com/elastic/elasticsearch/search?q=testFromJson%28%29\u0026unscoped_q=testFromJson%28%29) in \nthe [Elasticsearch](https://github.com/elastic/elasticsearch/) GitHub repository there can\nbe found plentifully examples on how to parse  a JSON string to a `org.elasticsearch.index.query.QueryBuilder`\ninstance.\n\n\n## Parsing a JSON query to a `QueryBuilder`\n\n```java\n\n    private static final NamedXContentRegistry XCONTENT_REGISTRY = new NamedXContentRegistry(\n            new SearchModule(\n                    Settings.EMPTY,\n                    false,\n                    Collections.emptyList()\n            ).getNamedXContents()\n    );\n\n    // ....\n\n    private static QueryBuilder parseQuery(String queryAsString) throws IOException {\n        var parser = JsonXContent.jsonXContent.createParser(\n                XCONTENT_REGISTRY,\n                LoggingDeprecationHandler.INSTANCE, queryAsString\n        );\n        return AbstractQueryBuilder.parseInnerQueryBuilder(parser);\n    }\n\n```\n\n\n## Customize a parsed `QueryBuilder` from a JSON query\n\nThis project contains the [ElasticPercolateQuerySearcherTest](src/test/java/com/findinpath/elasticsearch/percolator/ElasticPercolateQuerySearcherTest.java) \nJUnit test class which:\n \n- retrieves the details of a news alert\n- parses the percolate query belonging to the news alert to a `org.elasticsearch.index.query.QueryBuilder`\n- modifies the query builder by adding an extra filter (e.g. : only the documents published after a certain date)\n- executes the query on the news index \n\n\n## Try out the tests\n\nThe tests on the project are based on [testcontainers](https://www.testcontainers.org/) library\nfor providing a lightweight, throwaway instance of [Elasticsearch](https://www.testcontainers.org/modules/elasticsearch/).\n \nRun the tests on the project by executing:\n`./gradlew test`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffindinpath%2Felastic-percolate-query-searcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffindinpath%2Felastic-percolate-query-searcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffindinpath%2Felastic-percolate-query-searcher/lists"}