3

In elasticsearch we have a type which has an array of objects. When trying to access from Kibana I am getting some inconsistencies while accessing

Here is an extract from my mapping,

{
    "myIndex-2017.08.22": {
        "mappings": {
            "typeA": {
                "properties": {
                    .
                    .
                    .
                    "Collection": {
                        "properties": {
                            .
                            .
                            .
                            "FileType": {
                                "type": "text"
                            }
                        }
                    }
                }
            }
        }
    }
}

Here I can have multiple objects in the Collection i.e., indexing it as an array. When I try too query using one FileType for example FileType: DOCX then I get some records with FileType as HTML as well.

When looking deeper I found that it is because some of the records which has two collection elements one with FileType: DOCX and one with FileType: HTML.

Why is filtering working like this ? Is there any other way to filter and get only FileType: DOCX and not display FileType: HTML.

Am running ES 5.3.

1 Answer 1

6

Elasticsearch flattens array fields out of the box, so

{
 "files" : [ 
    {
      "name" : "name1",
      "fileType" :  "doc"
    },
    {
      "name" : "name2",
      "fileType" :  "html"
    }
  ]}

becomes:

{
  "files.name" : [ "name1", "name2" ],
  "files.fileType" :  [ "doc", "html" ]
}

If you want to search for the objects itself in this array you have to use the nested datatype in the mapping of the collection:

{
    "myIndex-2017.08.22": {
        "mappings": {
            "typeA": {
                "properties": {
                    .
                    .
                    .
                    "Collection": {
                        "type": "nested",
                        "properties": {
                            .
                            .
                            .
                            "FileType": {
                                "type": "text"
                            }
                        }
                    }
                }
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

This seems to be working in elasticsearch, but I am not able to query these fields in Kibana.
Quick googling shows that this is not supported by Kibana at all :( (github.com/elastic/kibana/issues/1084). Is there a way where we can make this work with Kibana as well.
I don't think so, that there is an easy solution with Kibana, when I read the comments.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.