### Install Elastix Dependency Source: https://github.com/werbitzky/elastix/blob/master/README.md This snippet shows how to add the Elastix library as a dependency in your Elixir project's `mix.exs` file. After adding the dependency, you need to run `mix deps.get` to fetch it. ```elixir def deps do [ {:elastix, ">= 0.0.0"} ] end ``` -------------------------------- ### Elasticsearch Document Operations (Map, Index, Search, Delete) Source: https://github.com/werbitzky/elastix/blob/master/README.md This example illustrates a typical workflow with Elasticsearch using Elastix: defining a mapping for a document type, indexing a document with specific data, searching for documents, and then deleting a document. It requires the Elasticsearch URL and details about the index and document type. ```elixir elastic_url = "http://localhost:9200" data = %{ user: "kimchy", post_date: "2009-11-15T14:12:12", message: "trying out Elastix" } mapping = %{ properties: %{ user: %{type: "text"}, post_date: %{type: "date"}, message: %{type: "text"} } } Elastix.Mapping.put(elastic_url, "twitter", "tweet", mapping) Elastix.Document.index(elastic_url, "twitter", "tweet", "42", data) Elastix.Search.search(elastic_url, "twitter", ["tweet"], %{}) Elastix.Document.delete(elastic_url, "twitter", "tweet", "42") ``` -------------------------------- ### Elastix Configuration: Custom Headers Source: https://github.com/werbitzky/elastix/blob/master/README.md Configures Elastix to add custom headers to all outgoing requests. This is done by providing a tuple `{Module, :function, [args]}` where the function is responsible for generating and returning the headers. An example shows how to add an AWS signature. ```elixir config :elastix, custom_headers: {MyModule, :add_aws_signature, ["us-east"]} defmodule MyModule do def add_aws_signature(request, region) do [{"Authorization", generate_aws_signature(request, region)} | request.headers] end defp generate_aws_signature(request, region) do # See: https://github.com/bryanjos/aws_auth or similar end end ``` -------------------------------- ### Download and Run Wisdom RESTClient Source: https://github.com/werbitzky/elastix/wiki/Automated-test-and-generate-RESTful-API-documentation-through-rest-client Instructions on how to download the Wisdom RESTClient JAR file and run the GUI application. It requires Java 1.7 or higher. ```bash Download JAR: restclient-1.2.jar Install Java 1.7 or higher. Double click restclient-1.2.jar to launch GUI. ``` -------------------------------- ### Running Elastix Tests with Elasticsearch Source: https://github.com/werbitzky/elastix/blob/master/README.md Instructions on how to set up and run the tests for the Elastix project. This involves having Elasticsearch running locally (e.g., via Docker), cloning the repository, fetching dependencies, and executing the tests with `mix test`. ```shell docker run -p 9200:9200 -it --rm elasticsearch:5.1.2 git clone git@github.com:werbitzky/elastix.git cd elastix mix deps.get mix test ``` -------------------------------- ### 下载和运行 Wisdom RESTClient Source: https://github.com/werbitzky/elastix/wiki/Automated-test-and-generate-RESTful-API-documentation-through-rest-client 下载 Wisdom RESTClient JAR 文件并运行 GUI 应用程序的说明。需要 Java 1.7 或更高版本。 ```bash 下载 JAR 包: restclient-1.2.jar 安装 Java 1.7 或更高版本。 双击 restclient-1.2.jar 即可运行工具。 ``` -------------------------------- ### Create Elasticsearch Index Source: https://github.com/werbitzky/elastix/blob/master/README.md Demonstrates how to create a new index in Elasticsearch using the Elastix client. It requires the Elasticsearch URL, the index name, and an optional map for index settings. ```elixir Elastix.Index.create("http://localhost:9200", "twitter", %{}) ``` -------------------------------- ### Elasticsearch Bulk Requests Source: https://github.com/werbitzky/elastix/blob/master/README.md Shows how to perform bulk operations in Elasticsearch using Elastix. This includes posting a list of operations (like indexing documents) and posting raw data. Options like `index`, `type`, and `httpoison_options` can be specified. ```elixir lines = [ %{index: %{_id: "1"}}, %{field: "value1"}, %{index: %{_id: "2"}}, %{field: "value2"} ] Elastix.Bulk.post(elastic_url, lines, index: "my_index", type: "my_type", httpoison_options: [timeout: 180_000]) # You can also send raw data: data = Enum.map(lines, fn line -> Poison.encode!(line) <> "\n" end) Elastix.Bulk.post_raw(elastic_url, data, index: "my_index", type: "my_type") ``` -------------------------------- ### Elastix Configuration: JSON and HTTPoison Options Source: https://github.com/werbitzky/elastix/blob/master/README.md Configures Elastix to use specific options for JSON parsing (e.g., using atoms for keys) and HTTP requests via HTTPoison. This allows customization of how data is encoded/decoded and how HTTP requests are handled, including connection pooling. ```elixir config :elastix, json_options: [keys: :atoms!], httpoison_options: [hackney: [pool: :elastix_pool]] ``` -------------------------------- ### Elastix Configuration: Shield, Username, Password Source: https://github.com/werbitzky/elastix/blob/master/README.md Configures Elastix to use Elasticsearch Shield for security. This involves setting the `shield` option to `true` and providing `username` and `password` credentials. ```elixir config :elastix, shield: true, username: "username", password: "password", ``` -------------------------------- ### Configure Elastix with Jason JSON Codec Source: https://github.com/werbitzky/elastix/blob/master/pages/custom-json-codec.md This Elixir code snippet demonstrates configuring the Elastix project to use the Jason library as its JSON codec. It simply sets the `json_codec` option to `Jason`. ```elixir config :elastix, json_codec: Jason ``` -------------------------------- ### Implement Elastix JSON Codec Behavior Source: https://github.com/werbitzky/elastix/blob/master/pages/custom-json-codec.md This Elixir code defines a `JiffyCodec` module that implements the `Elastix.JSON.Codec` behavior. It provides `encode!` and `decode` functions using the `:jiffy` library for JSON operations. ```elixir defmodule JiffyCodec do @behaviour Elastix.JSON.Codec def encode!(data), do: :jiffy.encode(data) def decode(json, opts \ []), do: {:ok, :jiffy.decode(json, opts)} end ``` -------------------------------- ### Configure Elastix with Jiffy JSON Codec Source: https://github.com/werbitzky/elastix/blob/master/pages/custom-json-codec.md This Elixir code snippet shows how to configure the Elastix project to use the Jiffy library for JSON encoding and decoding. It specifies the `json_codec` as `JiffyCodec` and sets `json_options` to `[:return_maps]`. ```elixir config :elastix, json_codec: JiffyCodec, json_options: [:return_maps] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.