4

I have seen similar questions posted, but of course, none are exactly what I am trying to do.

When I run the query below I get this error:

"reason": "[nested] failed to find nested object under path [contentGroup]"

I think the problem is contentGroup.name does not exist because contentGroup is an array not an object. It needs to be something like this: contentGroup[0].name and contentGroup[1].name But I can't figure out how to do that.

Another thing that might be wrong is that I have two items nested within each other, I don't know if that is right or not.

Any help would be great!

My mapping:

{
"mappings": {
    "articles": {
        "properties": {
            "contentGroups": {
                "type": "nested",
                "properties": {
                    "contentGroup": {
                        "type": "nested",
                        "properties": {
                            "id": {
                            "type": "string"
                            },
                            "name": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        }
    }
}

What gets created when I input in an article ( Note the array being created ):

"contentGroups": {
"contentGroup": [
    {
        "name": "Breaking",
        "id": "104"
    },
    {
        "name": "News",
        "id": "22"
    }
]

My query:

{
"query": {
    "bool": {
        "must": [
            { "match": { "headline": "whatever" }}, 
            {
                "nested": {
                    "path": "contentGroup",
                    "query": {
                        "bool": {
                            "must": [
                                { "match": { "contentGroup.name": "Breaking" }}
                            ]
                        }
                    }
                }
            }
        ]
    }
}

1 Answer 1

3

You should use simpler mapping:

{
  "mappings": {
    "articles": {
      "properties": {
        "contentGroups": {
          "properties": {
            "id": {
              "type": "string"
            },
            "name": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}

Each field in elasticsearch already supports multiple values, no need to specify this.

Sign up to request clarification or add additional context in comments.

1 Comment

This worked for me! Such a simple solution too! Thank you!

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.