0

I have an array field with type "nested". In this field i have multiple objects. This is JSON example:

{
  "users" : [
    {
      "first" : "John",
      "last" :  "Smith"
    },
    {
      "first" : "Alice",
      "last" :  "White"
    }
  ]
}

I expect the same structure after indexing. This is part of my mapping:

},
"users": {
    "dynamic": false,
    "type": "nested",
    "properties": {
        "first": {
            "type": "text"
         },
         "last": {
             "type": "text"
        },
    }
}

But after indexing i get this structure: enter image description here

    
users
    
[
  {
    "first": [
      "John"
    ],
    "last": [
      "Smith"
    ],
  },
  {
    "first": [
      "Alice"
    ],
    "last": [
      "White"
    ],
  },]

What i am doing wrong? Is this behavior expected? How i can handle nested objects?

I need only text fields, not text fields in array. Search works fine, but data format after mapping is confusing.

Delete indexes, change mapping, refresh indexes. Set dynamic: true and false. Change field types.

1 Answer 1

1

It's working as expected for me. I'm using ES v8.

enter image description here

PUT my-index-000001
{
  "mappings": {
    "properties": {
      "users": {
        "dynamic": false,
        "type": "nested",
        "properties": {
          "first": {
            "type": "text"
          },
          "last": {
            "type": "text"
          }
        }
      }
    }
  }
}

PUT my-index-000001/_doc/1
{
  "group" : "fans",
  "users" : [
    {
      "first" : "John",
      "last" :  "Smith"
    },
    {
      "first" : "Alice",
      "last" :  "White"
    }
  ]
}

GET my-index-000001/_search
{
  "query": {
    "nested": {
      "path": "users",
      "query": {
        "bool": {
          "must": [
            { "match": { "users.first": "Alice" }},
            { "match": { "users.last":  "White" }} 
          ]
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Yes, you're right. For some reason, in the Kibana interface, such fields look like an array. But they are actually stored as regular values. After your answer, I guessed to make an API request and found out this difference in display.
Happy to hear you solved it.

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.