문제

If I add new string field in document then mapping for it is automatically created and here it is string which is ok:

curl -XPOST http://localhost:9200/jakis/typ -d '{"imie": "John"}'

result:

{
  "ok": true,
  "_index": "jakis",
  "_type": "typ",
  "_id": "GY5AYdaVRH-Vg-XcBQzWYw",
  "_version": 1
}

curl -XGET http://localhost:9200/jakis/_mapping

result:

{
  "jakis": {
    "typ": {
      "properties": {
        "imie": {
          "type": "string"
        }
      }
    }
  }
}

However if I add a field with the same name as this one already present in mapping but of different type (in mapping it is string, here I add integer) then Elasticsearch happily adds new document but new mapping for integer field is not placed in type mapping:

curl -XPOST http://localhost:9200/jakis/typ -d '{"imie": 2}'      

result:

{
  "ok": true,
  "_index": "jakis",
  "_type": "typ",
  "_id": "zLpMl5_RSTiceFFG31mj6Q",
  "_version": 1
}

curl -XGET http://localhost:9200/jakis/typ/_mapping

result:

{
  "typ": {
    "properties": {
      "imie": {
        "type": "string"
      }
    }
  }
}

The question is - will be this field added as integer or will it be converted to string? Is there some way to report it as error?

도움이 되었습니까?

해결책

it will convert number 2 into the string "2". The only time it will throw an exception is when there are no appropriate type converter or when ever it can not do a conversion (for example adding big integer into integer field)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top