elastic / elasticsearch-rs

Official Elasticsearch Rust Client
https://www.elastic.co/guide/en/elasticsearch/client/rust-api/current/index.html
Apache License 2.0
705 stars 72 forks source link

Map URL parts to builders #2

Closed russcam closed 4 years ago

russcam commented 4 years ago

Each API endpoint maps to one or more URL paths, where each path may contain placeholders for URL parts that should be replaced with values supplied by the user. For example, _search has the following paths in 7.3.1 Rest API spec

/_search
/{index}/_search

The builder for the _search API, Search, should contain an index field that when set, results in the API call using the path specifying the index. It's envisaged that this will require

  1. An index field on the `Search struct
  2. An index function on Search implementation that sets the index field
  3. An implementation in the Sender trait send() function that checks whether index has a value and if it does, creates a path by replacing {index} in /{index}/_search with the index value, and uses this for the API function.

This implementation can be entirely generated from the REST API spec.

russcam commented 4 years ago

This has been implemented in 08dd846e83699ca6ac72232b66864d0b7d5b46ff, patterning matching on tuples of the optional URL parts, where each optional part may be set or not (Some(T) or None). An optional part is a URL part that is not required by all URL variants for an API.

This implementation is problematic per the commit message in 08dd846e83699ca6ac72232b66864d0b7d5b46ff. Closing this issue in favour of opening a new issue to track replacing the implementation with enums