-
Notifications
You must be signed in to change notification settings - Fork 533
[Feature] Handling Selecting Inner Fields on Inner Objects #31
Conversation
…earch returns the inner fields in this format '_source.inner_object', '_source.inner_object.inner_key'. I need this behaviour to be properly handled in my app, as I have some large keys I do not want to serialize on inner object, so I like cherry-picking them, I've added handling for this syntax.
I'm not sure I understand the problem, and even less the code. What is the real issue here? What is the actual response from ES? (I suspect the issue is that ES returns pseudo-JSON like |
Query:
Response:
The code:
In the example code I've posted note the key '_source.meta' this is also provided in the initial query. |
…wice when updating unit tests.
OK, thanks for clarification. I think this unexpected behaviour of ElasticSearch. The documentation at http://www.elasticsearch.org/guide/reference/api/search/fields.html states:
And this is probably not the case. Another user, @vhyza has already hit this issue as well. In your case, you should have a Now, you are working around this by setting fields to
and not like this:
That response would be properly parsed by the @kimchy, do you have any ideas or suggestions for this? |
@kimchy here is gist with example: https://gist.github.com/1018584. I tried it on ES 0.16.1 and on master with last commit elastic/elasticsearch@6382ddf43cea9a6a88a2 |
I agree it seems like weird behaviour with how ES (or maybe Lucene?) is handling object fields behind the scenes. The only way I could figure out to cherry-pick the 'meta' field was using '_source.meta', which required this patch. I'm going to dig into the ES code a little bit, maybe this will give me an excuse to submit my first patch to that project -- I'll keep you posted. |
The way ES works in its decision to try and load fields is from _source or not is only for non compound fields (like |
@kimchy, so it's intentional, that ES returns JSON like If so, then client libraries have to take this into account and strip the |
Yes, since it started from the fact that you had to explicitly specify |
Cool, thanks for the clarification, I'm glad it wasn't just weird behaviour that I was noticing. |
OK, what a pity :) But OK, I'd probably then:
|
Yeah, that's what my patch is attempting to do ;) With unit tests even. |
@bcoe, yes, I'll have a look if it could be simplified somehow... |
…rom ES [#31] The underlying issue is this, reported by @vhyza: <#31 (comment)> For a query with limited fields, such as: <http://localhost:9200/fields_test/_search?q=shay&fields=message,_source.person> ES returns JSON like this: fields: { message: "This is a tweet!" _source.person: { sid: "12345" name: { last_name: "Banon" first_name: "Shay" } } } Notice the `_source` prefix for the `person`. It gets even more tricky with nested hashes such as `_source.track.info.duration`. This should be converted into a regular Hash and accessible as `track.info.duration.minutes` property of the result. See the test suite for example data. This commit closes issue #31.
I have cheated and used |
[Feature] When selecting specific fields on an inner object, Elasticsearch returns the inner fields in this format '_source.inner_object', '_source.inner_object.inner_key'. I need this behaviour to be properly handled in my app, as I have some large keys I do not want to serialize on inner object, so I like cherry-picking them, I've added handling for this syntax.
Here's an example of the underlying Elastic search request:
curl -X POST "http://localhost:9200/foo-attachments-index/_search?pretty=true" -d '{"size":5,"from":0,"fields":["uuid","hash","file_extension","file_size","filename","type","external_id","downloadable","date","sender","visible","thumbnail_created","shared","large_thumbnail_created","share_url","meta","_source.meta.image_width"],"sort":["_score"],"query":{"bool":{"must":[{"query_string":{"query":"*"}},{"term":{"user_uuid":"foo"}}]}}}'