Elasticsearch fails silently if document has mapping mismatch for a field

后端 未结 2 1836
一生所求
一生所求 2021-02-06 01:59

I am facing a weird issue with Elasticsearch. My mapping specifies that a certain field is of type long. Now accidentally I was trying to index some documents which

2条回答
  •  爱一瞬间的悲伤
    2021-02-06 02:21

    If you set ignore_malformed string to false. It would not index the document if it is malformed but throws an exception. At least in elasticsearch 1.6.0.

    Example:

    put test
    
    put test/test/_mapping 
    {
        "properties" : {
            "title" : {"type" : "string"},
            "data" : {"type": "long" ,"ignore_malformed":false}
    
        }
    }
    
    put test/test/1
    {
        "data" : "1",
        "title" : "valid coerce string to number"
    }
    
    put test/test/2
    {
        "data" : "hello",
        "title" : "invalid number"
    }
    
    #Failed Response
    {
       "error": "MapperParsingException[failed to parse [data]]; nested: NumberFormatException[For input string: \"hello\"]; ",
       "status": 400
    }
    
    Query with Get fails
    
    get test/test/2
    
    
    {
       "_index": "test",
       "_type": "test",
       "_id": "2",
       "found": false
    }
    

提交回复
热议问题