1

The following are the contents of config/default_mapping.json:

{
    "_default_" : [
    {
        "int_template" : {
                "match": "*",
                "match_mapping_type": "int",
                "mapping": {
                        "type": "string"
                }
        }
    ]
}

Want i want ES to do is to pick out all numbers from my logs and map them as strings.

Use case-

After clearing all indexes- curl -XDELETE 'http://localhost:9200/_all', i run this to send the following to ES (through fluentd's tailf plugin)-

echo "{\"this\" : 134}" >> /home/user/logs/program-data/logs/tiger/tiger.log

Elastic happily creates the initial indexes. Now, to test weather my default_mapping works, i send a string at the value where i previously sent an int.

echo "{\"this\" : \"ABC\"}" >> /home/user/logs/program-data/logs/tiger/tiger.log

Exception caught by ES-

org.elasticsearch.index.mapper.MapperParsingException: failed to parse [this]
    at org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(AbstractFieldMapper.java:398)
    at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(ObjectMapper.java:618)
    at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:471)
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:513)
    at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:457)
    at org.elasticsearch.index.shard.service.InternalIndexShard.prepareCreate(InternalIndexShard.java:342)
    at org.elasticsearch.action.bulk.TransportShardBulkAction.shardIndexOperation(TransportShardBulkAction.java:401)
    at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:155)
    at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:556)
    at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:426)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:701)
Caused by: java.lang.NumberFormatException: For input string: "ABC"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Long.parseLong(Long.java:438)
    at java.lang.Long.parseLong(Long.java:478)
    at org.elasticsearch.common.xcontent.support.AbstractXContentParser.longValue(AbstractXContentParser.java:89)

What could be wrong here?

Update-

My default_mapping.json now looks like-

{
        "_default_": {
            "dynamic_templates": [
                {
                    "string_template": {
                        "match": "*",
                        "mapping": {
                            "type": "string"
                        }
                    }
                }
            ]
        }
}

1 Answer 1

1

First of all, I'd suggest not to use file system based configuration or mappings. Just do it via api.

Your mapping is malformed, as you have the type name (_default_) but you don't specify that what you are submitting is a dynamic template.

As for the content, I'd remove that match_mapping_type if you want to map everything as a string.

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

9 Comments

Could you perhaps do a pastebin of the proper json configuration? i have been struggling with this for hours now.
Have a look here for the right json, there's an example...
If i want this number to string change across the board, what should i put in the place of "person" in the given json example? *?
person is the typename in the example, _default_ is good in your case, it will apply to all types. What you forgot is the dynamic_templates part under it.
Confirming that the file would be called default_mapping.json and would be placed in config/default_mapping.json
|

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.