user1589188
user1589188

Reputation: 5736

How to see what are the analysed tokens being indexed in Elasticsearch

Given a source value "New-Value", say I have a keyword field, I know it is indexed as "New-Value" untouched, and then a text field, I know it is indexed as "new", "value" two lowercase tokens. Now for some custom fields with some custom analyser, instead of carefully tracing the index definition myself, is there an easy way to query what is being indexed from an existing index?

Upvotes: 0

Views: 321

Answers (1)

Amit
Amit

Reputation: 32376

You need to enable the fielddata in order to achieve it, its not enabled on text fields, after that you can get the tokens created for a field in ES inverted index:

Complete example

Index mapping

{
    "mappings" :{
        "properties" :{
            "foo" :{
                "type" : "text",
                "fielddata": true
            }
        }
    }
}

Index sample docs

{
    "foo" : "Bar"
}

{
    "foo" : "Bar and Baz"
}

And search query to fetch the tokens in inverted index for both sample docs

{
    "query": {
        "match_all": {}
    },
    "docvalue_fields": [
        {
            "field": "foo"
        }
    ]
}

And result

 "hits": [
            {
                "_index": "myindex",
                "_type": "_doc",
                "_id": "1",
                "_score": 1.0,
                "_source": {
                    "foo": "Bar"
                },
                "fields": {
                    "foo": [
                        "bar"
                    ]
                }
            },
            {
                "_index": "myindex",
                "_type": "_doc",
                "_id": "2",
                "_score": 1.0,
                "_source": {
                    "foo": "Bar and Baz"
                },
                "fields": {
                    "foo": [
                        "and",
                        "bar",
                        "baz"
                    ]
                }
            }
        ]

Upvotes: 1

Related Questions