{"id":24761657,"url":"https://github.com/driebit/mod_elasticsearch","last_synced_at":"2026-04-29T08:05:09.525Z","repository":{"id":21360029,"uuid":"24677221","full_name":"driebit/mod_elasticsearch","owner":"driebit","description":"Zotonic Elasticsearch module","archived":false,"fork":false,"pushed_at":"2024-03-15T07:08:08.000Z","size":254,"stargazers_count":1,"open_issues_count":8,"forks_count":2,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-23T13:15:55.336Z","etag":null,"topics":["elasticsearch","erlang","zotonic"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/driebit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":"support/elasticsearch.erl","governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2014-10-01T12:16:56.000Z","updated_at":"2022-06-21T12:39:13.000Z","dependencies_parsed_at":"2024-03-15T08:26:32.801Z","dependency_job_id":"7ca80300-94d2-4611-a456-80567d68978c","html_url":"https://github.com/driebit/mod_elasticsearch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/driebit/mod_elasticsearch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/driebit%2Fmod_elasticsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/driebit%2Fmod_elasticsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/driebit%2Fmod_elasticsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/driebit%2Fmod_elasticsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/driebit","download_url":"https://codeload.github.com/driebit/mod_elasticsearch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/driebit%2Fmod_elasticsearch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32416147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T06:29:02.080Z","status":"ssl_error","status_checked_at":"2026-04-29T06:29:00.631Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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","erlang","zotonic"],"created_at":"2025-01-28T19:18:39.600Z","updated_at":"2026-04-29T08:05:09.485Z","avatar_url":"https://github.com/driebit.png","language":"Erlang","funding_links":[],"categories":[],"sub_categories":[],"readme":"mod_elasticsearch\n=================\n\n[![Build Status](https://travis-ci.com/driebit/mod_elasticsearch.svg?branch=master)](https://travis-ci.com/driebit/mod_elasticsearch)\n\nThis [Zotonic](https://github.com/zotonic/zotonic) module gives you more relevant search results\nby making resources searchable through  \n[Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html).\n\nNote\n----\n\nThis module uses Elastic Search 5.x, which has support for _Types_.\n\nFor Elastic 7+, use https://github.com/driebit/mod_elasticsearch2\n\nInstallation\n------------\n\nmod_elasticsearch acts as a bridge between Zotonic and the [tsloughter/erlastic_search](https://github.com/tsloughter/erlastic_search)\nErlang library, so install that and its dependencies first by adding them to `deps` in `zotonic.config`:\n\n```erlang\n{deps, [\n    %% ...\n    {erlastic_search, \".*\", {git, \"https://github.com/tsloughter/erlastic_search.git\", {tag, \"master\"}}},\n    {hackney, \".*\", {git, \"https://github.com/benoitc/hackney.git\", {tag, \"1.6.1\"}}},\n    {jsx, \".*\", {git, \"https://github.com/talentdeficit/jsx.git\", {tag, \"2.8.0\"}}}      \n]}\n```\n\nConfiguration\n-------------\n\nTo configure the Elasticsearch host and port, edit your \n[erlang.config](http://docs.zotonic.com/en/latest/ref/configuration/zotonic-configuration.html)\nfile:\n\n```erlang\n[\n    %% ...\n    {erlastic_search, [\n        {host, \u003c\u003c\"elasticsearch\"\u003e\u003e}, %% Defaults to 127.0.0.1\n        {port, 9200}                 %% Defaults to 9200\n    ]},\n    %% ...\n].\n```\n\nSearch queries\n--------------\n\nWhen mod_elasticsearch is enabled, it will direct all search operations of the \n‘query’ type to Elasticsearch:\n\n```erlang\nz_search:search({query, Args}, Context).\n```\n\nFor `Args`, you can pass all regular Zotonic [query arguments](http://docs.zotonic.com/en/latest/developer-guide/search.html#query-arguments),\nsuch as:\n\n```erlang\nz_search:search({query, [{hasobject, 507}]}, Context).\n````\n\n### Query context filters\n\nThe `filter` search argument that you know from Zotonic will be used in\nElasticsearch’s [filter context](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-filter-context.html).\nTo add filters that influence score (ranking), use the `query_context_filter`\ninstead. The syntax is identical to that of `filter`:\n\n```erlang\nz_search:search({query, [{query_context_filter, [[\"some_field\", \"value\"]]}]}, Context).\n```\n\n### Extra query arguments\n\nThis module adds some extra query arguments on top of Zotonic’s default ones.\n\nTo find documents that have a field, whatever its value (make sure to pass \n`exists` as atom): \n\n```erlang\n{filter, [\u003c\u003c\"some_field\"\u003e\u003e, exists]}\n```\n\nTo find documents that do not have a field (make sure to pass `missing` as \natom): \n\n```erlang\n{filter, [\u003c\u003c\"some_field\"\u003e\u003e, missing]}\n````\n\nFor a [match phrase prefix query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html),\nuse the `prefix` argument:\n\n```erlang\nz_search:search({query, [{prefix, \u003c\u003c\"Match this pref\"\u003e\u003e}]}, Context).\n```\n\nTo exclude a document:\n\n```erlang\n{exclude_document, [Type, Id]}\n```\n\nTo supply a custom [`function_score`](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html) \nclause, supply one or more `score_function`s. For instance, to rank recent\narticles above older ones:\n\n```erlang\nz_search:search(\n    {query, [\n        {text, \"Search this\"},\n        {score_function, #{\n            \u003c\u003c\"filter\"\u003e\u003e =\u003e [{cat, \"article\"}],\n            \u003c\u003c\"exp\"\u003e\u003e =\u003e #{\n                \u003c\u003c\"publication_start\"\u003e\u003e =\u003e #{\n                    \u003c\u003c\"scale\"\u003e\u003e =\u003e \u003c\u003c\"30d\"\u003e\u003e\n                }\n            }\n        }}\n    ]},\n    Context\n).\n```\n\nNotifications\n-------------\n\n### elasticsearch_fields\n\nObserve this foldr notification to change the document fields that are queried.\nYou can use Elasticsearch [multi_match syntax](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html)\nfor boosting fields:\n\n```erlang\n%% your_site.erl\n\n-export([\n    % ...\n    observe_elasticsearch_fields/3\n]).\n\nobserve_elasticsearch_fields({elasticsearch_fields, QueryText}, Fields, Context) -\u003e\n    %% QueryText is the search query text\n\n    %% Add or remove fields: \n    [\u003c\u003c\"some_field\"\u003e\u003e, \u003c\u003c\"boosted_field^2\"\u003e\u003e|Fields].   \n```\n\n### elasticsearch_put\n\nObserve this notification to change the resource properties before they are\nstored in Elasticsearch. For instance, to store their zodiac sign alongside \nperson resources:\n\n```erlang\n%% your_site.erl\n\n-include_lib(\"mod_elasticsearch/include/elasticsearch.hrl\").\n\n-export([\n    % ...\n    observe_elasticsearch_put/3\n]).\n\n-spec observe_elasticsearch_put(#elasticsearch_put{}, map(), z:context()) -\u003e map().\nobserve_elasticsearch_put(#elasticsearch_put{id = Id}, Props, Context) -\u003e\n    case m_rsc:is_a(Id, person, Context) of\n        true -\u003e\n            Props#{zodiac =\u003e calculate_zodiac(Id, Context)};\n        false -\u003e\n            Props\n    end.\n```\n\nLogging\n-------\n\nBy default, mod_elasticsearch logs outgoing queries at the debug log level. To\nsee them in your Zotonic console, change the minimum log level to debug:\n\n```erlang\nlager:set_loglevel(lager_console_backend, debug).\n```\n\nHow resources are indexed\n-------------------------\n\nContent in all languages is stored in the index, following the \n[one language per field](https://www.elastic.co/guide/en/elasticsearch/guide/current/one-lang-fields.html)\nstrategy: \n\n\u003e Each translation is stored in a separate field, which is analyzed according to\n\u003e the language it contains. At query time, the user’s language is used to boost\n\u003e fields in that particular language.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdriebit%2Fmod_elasticsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdriebit%2Fmod_elasticsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdriebit%2Fmod_elasticsearch/lists"}