Elasticsearch Reindex отображает данные о местоположении в геоформ - PullRequest
0 голосов
/ 18 сентября 2018

Я записал некоторые данные в Elasticsearch.Но мой шаблон не работал должным образом, и мои данные о местоположении отображаются динамически.Я хочу переиндексировать все данные с помощью скрипта запроса.Как я могу преобразовать данные местоположения в гео-форму?

Пример данных:

{
  "deviceId": "dev1",
  "location": {
     "type": "Point",
     "coordinates": [
          28.891983032226562,
          41.02446333535115
     ]
  }
}

type поле сопоставлено text и coordinates сопоставлено float.

test3 запрос сопоставления index put:

PUT /test3
{
    "mappings": {
        "doc": {
            "properties": {
                "location": {
                    "type": "geo_shape",
                    "tree": "quadtree",
                    "precision": "100m"
                }
            }
        }
    }
}

Мой скрипт переиндексации (отредактировано):

POST _reindex
{

  "size": 1000,
  "source": {

    "index": "test"
    , "query": {
      "constant_score": {
      "filter": {
        "exists": {
          "field": "location"
        }
      }
    }
    }
  },
  "dest": {
    "index": "test3"
  },
  "script":{
    "inline": "if(ctx._source.location.size()>1) {ctx._source.templocation=ctx._source.remove('location'); ctx._source['location.type'] = 'Point';  ctx._source['location.coordinates'] = ctx._source.templocation; ctx._source.remove('templocation'); } "
  }
}

Ответ Elasticsearch:

{
  "took": 172,
  "timed_out": false,
  "total": 2,
  "updated": 0,
  "created": 0,
  "deleted": 0,
  "batches": 1,
  "version_conflicts": 0,
  "noops": 0,
  "retries": {
    "bulk": 0,
    "search": 0
  },
  "throttled_millis": 0,
  "requests_per_second": -1,
  "throttled_until_millis": 0,
  "failures": [
    {
      "index": "test3",
      "type": "data",
      "id": "AWXsdV-z29dKQeP_vT68",
      "cause": {
        "type": "illegal_argument_exception",
        "reason": "[location] is defined as an object in mapping [data] but this name is already used for a field in other types"
      },
      "status": 400
    },
    {
      "index": "test3",
      "type": "data",
      "id": "AWXsdVAP29dKQeP_vT67",
      "cause": {
        "type": "illegal_argument_exception",
        "reason": "[location] is defined as an object in mapping [data] but this name is already used for a field in other types"
      },
      "status": 400
    }
  ]
}

Результат для curl -XGET localhost:9200/test3

{
  "test3": {
    "aliases": {},
    "mappings": {
      "doc": {
        "properties": {
          "location": {
            "type": "geo_shape",
            "tree": "quadtree",
            "precision": "100.0m"
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1537333568669",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "K78hBgskSkKIg-Itb7uqvA",
        "version": {
          "created": "5060499"
        },
        "provided_name": "test3"
      }
    }
  }
}

1 Ответ

0 голосов
/ 19 сентября 2018

В вашем сценарии есть опечатка, необходимо убрать одну висящую квадратную скобку

"inline": "... ctx._source['location.coordinates'] = ctx._source.templocation]; ctx._source.remove('templocation'); } "
                                                                             ^
                                                                             |
                                                                        remove this
...