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

One request mapping #111

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

RoxasShadow
Copy link
Contributor

Hello!

I made this changes quite a while ago but then I forgot to open a PR for them.

The changes consist in:

  • replacing maplit with pure JSON objects provided by serde
  • send the mapping to elasticsearch just in one call so that it's possible to create more complex relations that it's not possible (or harder) to create in multiple steps (i.e. using _parent)

Copy link
Owner

@benashford benashford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, tidies up a few rough-edges. I have a few questions in-line that would help me figure out where this fits into the big-picture.

@@ -776,9 +776,26 @@ pub struct SearchHitsHitsResult<T> {
#[serde(rename="_routing")]
pub routing: Option<String>,
pub fields: Option<Value>,
pub highlight: Option<HighlightResult>
pub highlight: Option<HighlightResult>,
pub inner_hits: Option<HashMap<String, Value>>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Value needed due to the potential of more-than-one different type coming back in the results? In which case its probably unavoidable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl<T> SearchHitsHitsResult<T>
where T: DeserializeOwned {

pub fn inner_hit<S>(&self, key: &str) -> Option<SearchHitsResult<S>> where S: DeserializeOwned {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should perhaps be a Result<Option<SearchHitsResult<S>>, EsError> so we can tell apart the difference between a missing value and a malformed value?

serde_json errors will auto-promote to EsErrors so replacing the .ok() on line 791 with a ? would do the trick with the larger return type.

Copy link
Contributor Author

@RoxasShadow RoxasShadow Jan 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't use ? as I found the need to specify to rustc what kind of error are we dealing with - aabd707

@@ -50,14 +51,17 @@ impl NestedQuery {
/// Has Child query
#[derive(Debug, Default, Serialize)]
pub struct HasChildQuery {
#[serde(rename="type")]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this :) it must have been missing for quite a while

max_children: Option<u64>
max_children: Option<u64>,
#[serde(skip_serializing_if="ShouldSkip::should_skip")]
inner_hits: Option<Value>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferably this would be a concrete type rather than Value, but the ElasticSearch documentation is... less than comprehensive on this matter. This seems to be the best reference: https://www.elastic.co/guide/en/elasticsearch/reference/1.5/search-request-inner-hits.html unless there's a better one somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link I sent you in the other comment is similar to this one - Although I agree that a concrete type would be way preferable, I find not using a Value quite a hard way here 😞

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of Inner Hits potentially returning more than one query? Yes, that's true.

We could have a hybrid option as there is some predictable structure. E.g. the "total" and "_id" fields, it's only really the "_source" field that needs to be a Value?

max_children: Option<u64>
max_children: Option<u64>,
#[serde(skip_serializing_if="ShouldSkip::should_skip")]
inner_hits: Option<Value>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also add the same to the HasParentQuery as the inner_hits field should in-theory work there too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it actually? https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html I can't find it here but in case sure, I can add inner_hits in there too. I will wait for a your response before to commit it just to double check I understood correctly what you mean :)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I've ever needed it on a has_parent query, and it's not mentioned in the documentation for it either. But it is mentioned here: "Inner hits can be used by defining a inner_hits definition on a nested, has_child or has_parent query and filter" it might be something that's missing from the documentation elsewhere.

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

Successfully merging this pull request may close these issues.

2 participants