0

I have a index that contains list of url as array

Schema:

{
    "locations": {
        "type": "keyword"
    }
}

example document

{
    "locations": [
        "https://google.com",
        "https://yahoo.com"
    ]
}

I want to use a transform to create a new index, which contains list of urls with number of occurrence.

I tried creating transform like this:

{
    "pivot": {
        "group_by": {
            "user_id": {
                "terms": {
                    "field": "userId"
                }
            }
        },
        "aggs": {
            "locations": {
                "terms": {
                    "field": "locations.raw",
                    "order": {
                        "_count": "desc"
                    }
                }
            }
        }
    }
    // source and dest definition here 
}

Transform was successfully created without error but resulting document always has locations as empty array. What am I missing here?

1 Answer 1

1

You don't have any locations.raw field in your mapping, hence why the array is empty.

So, in your transform you simply need to refer to locations instead

{
    "pivot": {
        "group_by": {
            "user_id": {
                "terms": {
                    "field": "userId"
                }
            }
        },
        "aggs": {
            "locations": {
                "terms": {
                    "field": "locations",            <--- change this
                    "order": {
                        "_count": "desc"
                    }
                }
            }
        }
    }
    // source and dest definition here 
}
Sign up to request clarification or add additional context in comments.

Comments

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.