点字段类型
编辑点字段类型
编辑point
数据类型有助于索引和搜索落在二维平面坐标系中的任意 x, y
对。
你可以使用Shape 查询来查询使用此类型的文档。
与geo_shape和geo_point一样,point
可以以 GeoJSON 和 Well-Known Text 格式指定。但是,为了方便和历史原因,还支持许多其他格式。总共有五种方式可以指定笛卡尔点,如下所示
resp = client.indices.create( index="my-index-000001", mappings={ "properties": { "location": { "type": "point" } } }, ) print(resp) resp1 = client.index( index="my-index-000001", id="1", document={ "text": "Point as an object using GeoJSON format", "location": { "type": "Point", "coordinates": [ -71.34, 41.12 ] } }, ) print(resp1) resp2 = client.index( index="my-index-000001", id="2", document={ "text": "Point as a WKT POINT primitive", "location": "POINT (-71.34 41.12)" }, ) print(resp2) resp3 = client.index( index="my-index-000001", id="3", document={ "text": "Point as an object with 'x' and 'y' keys", "location": { "x": -71.34, "y": 41.12 } }, ) print(resp3) resp4 = client.index( index="my-index-000001", id="4", document={ "text": "Point as an array", "location": [ -71.34, 41.12 ] }, ) print(resp4) resp5 = client.index( index="my-index-000001", id="5", document={ "text": "Point as a string", "location": "-71.34,41.12" }, ) print(resp5)
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
const response = await client.indices.create({ index: "my-index-000001", mappings: { properties: { location: { type: "point", }, }, }, }); console.log(response); const response1 = await client.index({ index: "my-index-000001", id: 1, document: { text: "Point as an object using GeoJSON format", location: { type: "Point", coordinates: [-71.34, 41.12], }, }, }); console.log(response1); const response2 = await client.index({ index: "my-index-000001", id: 2, document: { text: "Point as a WKT POINT primitive", location: "POINT (-71.34 41.12)", }, }); console.log(response2); const response3 = await client.index({ index: "my-index-000001", id: 3, document: { text: "Point as an object with 'x' and 'y' keys", location: { x: -71.34, y: 41.12, }, }, }); console.log(response3); const response4 = await client.index({ index: "my-index-000001", id: 4, document: { text: "Point as an array", location: [-71.34, 41.12], }, }); console.log(response4); const response5 = await client.index({ index: "my-index-000001", id: 5, document: { text: "Point as a string", location: "-71.34,41.12", }, }); console.log(response5);
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
字段检索。