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

mattiassvedhem opened this Issue Mar 25, 2013 · 4 comments


None yet
2 participants

mattiassvedhem commented Mar 25, 2013

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


mattiassvedhem commented Mar 25, 2013

I monkey patched it like this:

module Tire
  module Results

    class Collection
     def __get_results_without_load(hits)
        if @wrapper == Hash
          hits.map 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.


karmi commented Mar 27, 2013

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.


mattiassvedhem commented Mar 27, 2013

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


karmi commented Mar 27, 2013

Grr, yes, #663 indeed :)

karmi closed this in d6e6d0a Jun 5, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment