如何使用Elasticsearch将映射放在json文件中

时间:2021-01-27 00:11:10

i have a lot of JSON documents with this structure :

我有很多这种结构的JSON文档:

"positions": [
    {
      "millis": 12959023,
      "lat": 49.01525113731623,
      "lon": 2.4971945118159056,
      "rawX": -3754,
      "rawY": 605,
      "rawVx": 0,
      "rawVy": 0,
      "speed": 9.801029291617944,
      "accel": 0.09442740907572084,
      "grounded": true
    },
    {
      "millis": 12959914,
      "lat": 49.01536940596998,
      "lon": 2.4967825412750244,
      "rawX": -3784,
      "rawY": 619,
      "rawVx": -15,
      "rawVy": 7,
      "speed": 10.841861737855924,
      "accel": -0.09534648619563282,
      "grounded": true
    }
...
}

i'm trying to map this JSON document with Elasticsearch by introducing a geo_point field to get document like the one below :

我正在尝试使用Elasticsearch映射此JSON文档,方法是引入geo_point字段以获取如下所示的文档:

"positions": [
        {
          "millis": 12959023,
          "location" : {
              "lat": 49.01525113731623,
              "lon": 2.4971945118159056,
           }          
          "rawX": -3754,
          "rawY": 605,
          "rawVx": 0,
          "rawVy": 0,
          "speed": 9.801029291617944,
          "accel": 0.09442740907572084,
          "grounded": true
        },
    ...
    }

PS : these documents are offered by an API.

PS:这些文件由API提供。

Thanks

谢谢

2 个解决方案

#1


0  

You could do something like this:

你可以这样做:

curl -XPUT 'http://localhost:9200/<indexname>/positions/_mapping' -d @yourjsonfile.json

Hope this SO helps!

希望这有助于!

#2


0  

If you can't modify the source, you need to pre-process your document before it gets indexed into elasticsearch.

如果您无法修改源,则需要在将文档索引到elasticsearch之前对其进行预处理。

  • If you are using elasticsearch < 5.0, you can use logstash and the mutate filter.
  • 如果您使用elasticsearch <5.0,则可以使用logstash和mutate过滤器。
  • If you are using elasticsearch >= 5.0 (my advice), use an ingest pipeline and the rename processor.
  • 如果您使用的是elasticsearch> = 5.0(我的建议),请使用摄取管道和重命名处理器。

#1


0  

You could do something like this:

你可以这样做:

curl -XPUT 'http://localhost:9200/<indexname>/positions/_mapping' -d @yourjsonfile.json

Hope this SO helps!

希望这有助于!

#2


0  

If you can't modify the source, you need to pre-process your document before it gets indexed into elasticsearch.

如果您无法修改源,则需要在将文档索引到elasticsearch之前对其进行预处理。

  • If you are using elasticsearch < 5.0, you can use logstash and the mutate filter.
  • 如果您使用elasticsearch <5.0,则可以使用logstash和mutate过滤器。
  • If you are using elasticsearch >= 5.0 (my advice), use an ingest pipeline and the rename processor.
  • 如果您使用的是elasticsearch> = 5.0(我的建议),请使用摄取管道和重命名处理器。