0

some docs saved with wrong type.

wrong doc: {"tgi": {"male": "0.11"}}

it should be: {"tgi": {"male": 0.11}}

the mapping is:

{
"properties": {
    "tgi": {
        "type": "nested",
        "properties": {
            "male": {
                "type": "float"
            }
        }
    }
}

}

question: how to query all wrong docs?

  • It completely depends on how you're indexing data. Mapping is correct, there is no issue with it. – Harshit Sep 03 '20 at 11:27
  • Also, you can't query the wrong documents. Just see in the code how the indexing of data is happening. – Harshit Sep 03 '20 at 11:27

2 Answers2

1

Your mapping is correct, i.e. the male field is of type float.

In your source document, "0.11" and 0.11 will be interpreted the same way by Elasticsearch because it will try to coerce the string value into a float, so nothing's really wrong per se.

Moreover, it sometimes makes more sense to store float numbers as strings in the source document because of the known precision issues with float numbers in Javascript/JSON. In that sense, the first document would be the "correct" one and the second one would be the "wrong" one.

None are actually wrong, both will work, yet the second one (with numerical float values) might probably incur precision issues in aggregations (sum, avg, etc)

Val
  • 207,596
  • 13
  • 358
  • 360
0

Your mapping is wrong. Your doc have no nested object. Just an object. In elastic, nested object are array of objects. Then reindex and it should work.

Corrected mapping:

{
"properties": {
    "tgi": {
        "properties": {
            "male": {
                "type": "float"
            }
        }
    }
}
Jaycreation
  • 2,029
  • 1
  • 15
  • 30
  • ths your answer, but i still neet to find out wrong docs. – user14214235 Sep 03 '20 at 10:29
  • I will have to investigate more : could you post the whole /_mapping info please ? do you have doc with 2 kinds of data format? could you post a response where you have both? – Jaycreation Sep 03 '20 at 10:37
  • 1
    @Jaycreation a nested document is not necessarily an array, it can also be a simple object, so the mapping is correct as it is. – Val Sep 03 '20 at 11:07