Alternative to Array type in Kibana


(Mikhael) #1

Hello everybody,

Before everything, I´m sorry for my bad english. I´ll try to be clear and brief.

I have a huge problem. I don´t know how can I do my mapping and show in Kibana the following things.

Everyone has name,age,and state that their was born. But each person can have more then one likes.
For example: foods, relax, beach, soccer, etc.

I know that Kibana doesn´t support Array, Nested or Object types. So I´m trying to do it the way I´m showing it down.

This is my mapping

PUT elastic
{
"mappings": {
"person": {
"_all": { "enabled": false },
"properties": {
"name": {"type": "keyword"},
"age" : {"type" : "keyword"},
"state": {"type": "keyword"},
"likes": {"type": "keyword"}
}
}
}
}

PUT elastic/person/1
{
"name": "Mikhael",
"age": "24",
"state": "SP",
"likes": "foods"
}

PUT elastic/person/2
{
"name": "Mikhael",
"age": "24",
"state": "SP",
"likes": "relax"
}

PUT elastic/person/3
{
"name": "James",
"age": "21",
"state": "SP",
"likes": "beach"
}

PUT elastic/person/4
{
"name": "Oliver",
"age": "24",
"state": "RJ",
"likes": "foods"
}

When I try to term in Kibana by age, likes and name. The count is incorrect. How you can see below.

The real value of count is three, not four.

Someone has a light at the end of the tunnel for me.

Thank you


(CJ Cenizal) #2

Hi Mikhael, I think you want to store all of your like values on a single field of a single person's document. I took a look at the Array datatype docs and it looks like you want something like this:

PUT elastic/person/1
{
  “name”: “Mikhael”,
  “age”: “24”,
  “state”: “SP”,
  “likes”: [“foods”, “relax”]
}

Does this help?

Thanks,
CJ


(Mikhael) #3

Hello CJ,

Yes, it helps in part.

Because sometimes I don´t know how many "likes" each person can have.
Today I know that I like foods and relax, but tomorrow maybe I'll like sports too.

EX:

I had the below document yesterday.

PUT elastic/person/1
{
“name”: “Mikhael”,
“age”: “24”,
“state”: “SP”,
“likes”: [“foods”, “relax”]
}

But,today I like sports too.

EX:

PUT elastic/person/1
{
“name”: “Mikhael”,
“age”: “24”,
“state”: “SP”,
“likes”: [“foods”, “relax”, “sports”]
}

How can I deal with this? Need I update my document?

Should I search for the existing name "Mikhael" than update the same document with the olds (foods,relax) and the new (sports) value of "likes"?

Thanks for your helping


(Mikhael) #4

Hello CJ,

I have another question. I was thinking about how my Kibana could show my below data.

PUT action
{
"mappings": {
"user": {
"_all": { "enabled": false },
"properties": {
"name": {"type": "keyword"},
"age" : {"type" : "keyword"},
"date": {"type": "date", "format": "dd/MM/yyyy HH:mm:ss"},
"action": {"type": "keyword"}
}
}
}
}

So, I add this document

PUT action/user/1
{
"name": "Mikhael",
"age": "24",
"date":["22/08/2017 09:00:00","22/08/2017 10:00:00"],
"action": ["opening","closing"]
}

But, take a look to my Kibana.

I can't understand. Why is it happen? How could I change it?

I was expecting:

date : 22/08/2017 09:00:00, action: opening
date : 22/08/2017 10:00:00, action : closing

Thank you for your attention


(system) #5

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.