点字段类型
编辑点字段类型编辑
point
数据类型有助于对二维平面坐标系中的任意 x, y
对进行索引和搜索。
您可以使用 形状查询 查询此类型的文档。
与 geo_shape 和 geo_point 一样,point
可以使用 GeoJSON 和 Well-Known Text 格式指定。但是,为了方便和历史原因,还支持许多其他格式。总共有五种指定笛卡尔点的方法,如下所示
response = client.indices.create( index: 'my-index-000001', body: { mappings: { properties: { location: { type: 'point' } } } } ) puts response response = client.index( index: 'my-index-000001', id: 1, body: { text: 'Point as an object using GeoJSON format', location: { type: 'Point', coordinates: [ -71.34, 41.12 ] } } ) puts response response = client.index( index: 'my-index-000001', id: 2, body: { text: 'Point as a WKT POINT primitive', location: 'POINT (-71.34 41.12)' } ) puts response response = client.index( index: 'my-index-000001', id: 3, body: { text: "Point as an object with 'x' and 'y' keys", location: { x: -71.34, y: 41.12 } } ) puts response response = client.index( index: 'my-index-000001', id: 4, body: { text: 'Point as an array', location: [ -71.34, 41.12 ] } ) puts response response = client.index( index: 'my-index-000001', id: 5, body: { text: 'Point as a string', location: '-71.34,41.12' } ) puts response
PUT my-index-000001 { "mappings": { "properties": { "location": { "type": "point" } } } } PUT my-index-000001/_doc/1 { "text": "Point as an object using GeoJSON format", "location": { "type": "Point", "coordinates": [-71.34, 41.12] } } PUT my-index-000001/_doc/2 { "text": "Point as a WKT POINT primitive", "location" : "POINT (-71.34 41.12)" } PUT my-index-000001/_doc/3 { "text": "Point as an object with 'x' and 'y' keys", "location": { "x": -71.34, "y": 41.12 } } PUT my-index-000001/_doc/4 { "text": "Point as an array", "location": [ -71.34, 41.12 ] } PUT my-index-000001/_doc/5 { "text": "Point as a string", "location": "-71.34,41.12" }
以 GeoJSON 格式表示为对象的点,带有 |
|
以 Well-Known Text POINT 格式表示的点: |
|
以对象形式表示的点,带有 |
|
以数组形式表示的点,格式为:[ |
|
以字符串形式表示的点,格式为: |
与 geo-point 字段类型不同,坐标 x
和 y
的顺序对于上述所有格式都是相同的。
提供给索引器的坐标是单精度浮点值,因此该字段保证与 Java 虚拟机提供的精度相同(通常为 1E-38
)。
point
字段的参数编辑
point
字段接受以下参数
如果为 |
|
|
如果为 |
接受一个点值,该值将替换任何显式的 |
排序和检索点编辑
目前无法对点进行排序或直接检索其字段。point
值只能通过 _source
字段检索。