Elasticsearch shows float types as string in output

I have a sample schema like this

"coordinate": {
    "properties": {
			  "geo": {
        "type": "geo_point"
      },
      "latitude": {
        "type": "float"
      },
      "longitude": {
        "type": "float"
      }
    }
  }

when I search in index, I got this result

 "coordinate": {
      "geo": {
          "lat": "55.86167039999999",
          "lon": "-4.2583345"
      },
      "latitude": "55.86167039999999",
      "longitude": "-4.2583345"
  }

however I expect the result in the search be float, not string type ( you can see the latitude , longitude result is string )

also when in rust, I use this type:

pub geo: Option<GeoPoint<DefaultGeoPointMapping>>,

I got the error that the geo expect an array with two numbers

where am I doing wrong?

Hi @Ata_Zangene

The "_source" will always reflect the source document as it arrived for indexing, even if the fields are correct...

Fields are "indexed" and searched and aggregated against... the _source is the source data.

Take a look at this and see if it helps

PUT discuss-test
{
  "mappings": {
    "properties": {
      "coordinate": {
        "properties": {
          "geo": {
            "type": "geo_point"
          },
          "latitude": {
            "type": "float"
          },
          "longitude": {
            "type": "float"
          }
        }
      }
    }
  }
}

POST discuss-test/_doc
{
  "coordinate": {
      "geo": {
          "lat": "55.86167039999999",
          "lon": "-4.2583345"
      },
      "latitude": "55.86167039999999",
      "longitude": "-4.2583345"
  }
}


POST discuss-test/_doc
{
  "coordinate": {
      "geo": {
          "lat": 55.86167039999999,
          "lon": -4.2583345
      },
      "latitude": 55.86167039999999,
      "longitude": -4.2583345
  }
}

GET discuss-test/_search
{
  "fields": ["*"]
}

# Result
# Notice the Fields are the right data types.

{
  "took": 26,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "discuss-test",
        "_id": "PYb75IwBy2LEDx_Ya9RU",
        "_score": 1,
        "_source": {
          "coordinate": {
            "geo": {
              "lat": "55.86167039999999",
              "lon": "-4.2583345"
            },
            "latitude": "55.86167039999999",
            "longitude": "-4.2583345"
          }
        },
        "fields": {
          "coordinate.geo": [
            {
              "coordinates": [
                -4.2583345,
                55.86167039999999
              ],
              "type": "Point"
            }
          ],
          "coordinate.longitude": [
            -4.2583346
          ],
          "coordinate.latitude": [
            55.86167
          ]
        }
      },
      {
        "_index": "discuss-test",
        "_id": "Pob75IwBy2LEDx_Ya9Rv",
        "_score": 1,
        "_source": {
          "coordinate": {
            "geo": {
              "lat": 55.86167039999999,
              "lon": -4.2583345
            },
            "latitude": 55.86167039999999,
            "longitude": -4.2583345
          }
        },
        "fields": {
          "coordinate.geo": [
            {
              "coordinates": [
                -4.2583345,
                55.86167039999999
              ],
              "type": "Point"
            }
          ],
          "coordinate.longitude": [
            -4.2583346
          ],
          "coordinate.latitude": [
            55.86167
          ]
        }
      }
    ]
  }
}
2 Likes

Correct. thank you very much for your help

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.