Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENHANCEMENT] Provide non-array based SearchParts for searching single a index #149

Open
oeed opened this issue Oct 6, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@oeed
Copy link

oeed commented Oct 6, 2020

Is your feature request related to a problem? Please describe.
95% of my queries are only ever on a single index and I've found it a bit difficult/unergonomic to try and search for these when they're not 'static. Because SearchParts::Index takes &[&str] you have to wrap the single string like &[my_str], which doesn't work in situation where you return the SearchParts by value, not reference, like this (it's a bit of a contrived example, but I've run in to it in various situations):

pub trait Index {
  fn name(&self) -> &str;

  fn search_parts<'a>(&'a self) -> SearchParts<'a> {
    SearchParts::Index(&[self.name()])
  }
}

You get a cannot return value referencing temporary value, returns a value referencing data owned by the current function error. My index names are dynamic and so can't be static, this becomes an issue because the variant requires a reference to an array of references, which I simply can't figure out how to do within a single struct.

I'm still a bit new to Rust though, so if there's actually a good solution to this I'd love to know, I haven't been able to find one though.

Describe the solution you'd like
I'm far from a Rust expert as I've said, so there may be better ways; but the idea that comes to mind is to simply providing additional variants.

i.e.

pub enum SearchParts<'b> {
    ...
    SingleIndex(&'b str)
}

The implementation of SearchParts looks fairly straight forward so I'd be happy to provide a PR if open to the idea.

Describe alternatives you've considered
With a few layers of indirection and nested structs this is possible, but it's rather messy and unergonomic.

@oeed oeed added the enhancement New feature or request label Oct 6, 2020
@russcam
Copy link
Contributor

russcam commented Dec 8, 2020

Hi @oeed, I think #126 is going in the direction that you're after. Ideally, you'd be able to do

let response = client
    .search("my_index")
    .q("title:Elasticsearch")
    .send()
    .await?;

In its current form this isn't yet possible, the nearest being

let response = client
    .search(&["my_index"][..])
    .q("title:Elasticsearch")
    .send()
    .await?;

It'd be good to revisit, to see how we might go about this. I think the parts enums will likely end up owning their inputs for this to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants