Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use parent-child relationships on Kibana?

On a relational DB, I have two tables connected by a foreign key, on a typical one-to-many relationship. I would like to translate this schema into ElasticSearch, so I researched and found two options: the nested and parent-child. My ultimate goal was to visualize this dataset in Kibana 4.

Parent-child seemed the most adequate one, so I'll describe the steps that I followed, based on the official ES documentation and a few examples I found on the web.

 curl  -XPUT http://server:port/accident_struct -d '
{
 "mappings" : {
  "event" : {
  },
  "details": {
      "_parent": {
        "type": "event" 
      } ,
   "properties" : {       
 }  
  }
 }
}
';

here I create the index accident_struct, which contains two types (corresponding to the two relational tables): event and details.

Event is the parent, thus each document of details has an event associated to it.

Then I upload the documents using the bulk API. For event:

{"index":{"_index":"accident_struct","_type":"event","_id":"17f14c32-53ca-4671-b959-cf47e81cf55c"}}
{values here...}

And for details:

{"index":{"_index":"accident_struct","_type":"details","_id": "1", "_parent": "039c7e18-a24f-402d-b2c8-e5d36b8ad220" }}

The event does not know anything about children, but each child (details) needs to set its parent. In the ES documentation I see the parent being set using "parent", while in other examples I see it using "_parent". I wonder what is the correct option (although at this point, none works for me).

The requests are successfully completed and I can see that the number of documents contained in the index corresponds to the sum of events + types.

I can also query parents for children and children for parents, on ES. For example:

curl -XPOST host:port/accident_struct/details/_search?pretty -d '{
    "query" : {
        "has_parent" : {
            "type" : "event",
                "query" : {
                    "match_all" : {}
                }
        }
    }
}'

After setting the index on Kibana, I am able to list all the fields from parent and child. However, if I go to the "discover" tab, only the parent fields are listed.

If I uncheck a box that reads "hide missing fields", the fields from the child documents are shown as grey out, along with an error message (see image)

enter image description here

Am I doing something wrong or is the parent-child not supported in Kibana4? And if it is not supported, what would be the best alternative to represent this type of relationship?

like image 775
doublebyte Avatar asked Jun 29 '15 13:06

doublebyte


People also ask

What is parent/child relationship in CRM?

In CRM, the parent child relationships are created by adding a Lookup Field in the child record to the parent record. You can also create the relationships directly by navigating to 1-N relationships or N-1 relationships (based if you are in the parent or child entity).

Is Elasticsearch good for relational data?

Elasticsearch provides more efficient and flexible indexing compared with relational databases. In a business system, many scenarios require generic searches, which are queries based on arbitrary field combinations. Elasticsearch data models adopt the Free Scheme mode and JavaScript Object Notation (JSON) format.

What is a parent child relationship in data?

In database management, a relationship between two files. The parent file contains required data about a subject, such as employees and customers. The child is the offspring; for example, an order is the child to the customer, who is the parent.


1 Answers

Per the comment in this discussion on the elastic site, P/C is, like nested objects, at least not supported in visualizations. Le sigh.

like image 72
Scott Avatar answered Sep 21 '22 01:09

Scott