1

Model:

class Item
    store :socket_store, accessors: [:sockets, :socket_count, :socket_link_count]
end

Mapping:

mapping do
  indexes :id,                    key: "value", index: :not_analyzed
  indexes :sockets,               type: "object"
  indexes :socket_count,          type: "integer"
  indexes :socket_link_count,     type: "integer"
end

But here's what my actual index looks like:

socket_cout and the othe 2 attributes are not at the root of the mapping, as if they were completely ignored.

I know I could create methods with a different name and add them to the to_indexed_json, but I would have guessed it should work as is.

2
  • Did you see there is an name inconsistency? Don't know if that is influencing something. linked_socket_count != socket_link_count Commented Mar 5, 2013 at 15:38
  • Oh right, sorry, I just recently renamed the field, but it was correct at the time. Fixed the question. Commented Mar 5, 2013 at 16:13

1 Answer 1

1

Ok, I got it.

Since the accessors of the key-value store are not actual attributes on the Item model, they need to be added as methods in the to_indexed_json method:

def to_indexed_json
    to_json(include: [:stats], exclude: [:sockets_store], methods: [:socket_count, :socket_link_count, :sockets])
end

And that's it!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.