I've got a tough one, which I think can only be solved by client code, but here goes:
My index has 4 documents:
{"_id": "user1__field1", "_source": {"object_id": "user1", "field_name": "field1", "value_int": 123}}
{"_id": "user1__field2", "_source": {"object_id": "user1", "field_name": "field2", "value_str": "hello"}}
{"_id": "user2__field1", "_source": {"object_id": "user2", "field_name": "field1", "value_int": 456}}
{"_id": "user2__field2", "_source": {"object_id": "user2", "field_name": "field2", "value_str": "world"}}
For many reasons, every user/field pair is a separate document, unlike most use cases, where all fields for a user are in one document.
I'd like to perform a search for all of user1's fields, but get all results in one document, instead of 2. When I search for {"query": {"term": {"object_id": "user1"}}}
, I obviously get 2 results.
I'd like to run a search that will return something like
{
"object_id": "user1",
"field1": 123,
"field2": "hello"
}
In a way that it's taking the value_* from each document and using the "field_name" field to name that field's value. Crazy, I know, but possible?