Home > Software design >  How to detect whether elasticsearch has enabled dynamic field
How to detect whether elasticsearch has enabled dynamic field

Time:11-01

I don't know whether my index has enabled/disabled dynamic field. When I use get index mapping command it just responses these informations:

GET /my_index1/_mapping
{
    "my_index1": {
        "mappings": {
            "properties": {
                "goodsName": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "auditTime": {
                    "type": "long"
                },
                "createUserId": {
                    "type": "long"
                }
            }
        }
    }
}

CodePudding user response:

If you don't explicitly set the dynamic to false or strict, it will be true by default. If you explicitly set that, you will see that in your mappings:

{
    "mappings": {
        "dynamic": false,
        "properties": {
            "name": {
                "type": "text"
            }
        }
    }
}

And when you index the following document:

{"name":"products", "clickCount":1, "bookingCount":2, "isPromoted":1}

Only the field name will be indexed, the rest won't. If you call the _mapping endpoint again, it will give you the exact mappings above.

  • Related