Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Where is `fields` going? (use _parent field in Item) #687

mattiassvedhem opened this Issue · 4 comments

2 participants


When specifying that I want to return _parent field it does not get included in the item.

Adding this to the query:

{ "fields":["_parent","_source"] }

Gives this result when http:ing ES:

  "_index" : "menus",
  "_type" : "row",
  "_id" : "4f99f997a2b279ec3d00255a",
  "_score" : 1.880604, 
  "_source" : { "all": "the", "source": "fields"},
  "fields" : {
    "_parent" : "4f99f98ea2b279ec3d002522"

I can see the _parent field being returned in the "hits" key. But it's not available in the Item class, Since it's a hash I think that the Item class initializer tries to instantiate a new Item with it. However, something probably goes wrong there since calling item.fields returns nil.

Edit: Looking at the source the problem is clearly in Tire::Results::Collection in the parsing

A check for fields key should probably be done and if it exists it should be updated with the other meta information


I monkey patched it like this:

module Tire
  module Results

    class Collection
     def __get_results_without_load(hits)
        if @wrapper == Hash
 do |h|
            document = {}

            # Update the document with content and ID
            document = h['_source'] ? document.update( h['_source'] || {} ) : document.update( __parse_fields__(h['fields']) )
            document.update( {'id' => h['_id']} )

            # Update the document with meta information
            meta = ['_score', '_type', '_index', '_version', 'sort', 'highlight', '_explanation', 'fields']
            meta.each { |key| document.update( {key => h[key]} || {} ) }

            # Return an instance of the "wrapper" class


It might be a naive solution, and it's a little bit weird to wrap fields in an Item instance, but I feel that it's more consistent with the way it's returned by ES. i.e not at the root.


Hi, this is a bug in the code -- see also #663, I think the correct solution is to update the document with both _source and _fields, if present. The patch in #663 needs just a couple of unit + integration tests.


@karmi cool, you mean #663, right? =)


Grr, yes, #663 indeed :)

@karmi karmi closed this issue from a commit
@jwaldrip jwaldrip [FIX] Merge returned `fields` with `_source` if both are returned
Previously, when asking for `_source` in `fields`, only the specific `fields`
have been returned, not the full _source.

The Elasticsearch behaviour has possibly changed here,
see <#31 (comment)>

Closes #663, closes #687, closes #712
@karmi karmi closed this in d6e6d0a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.