点字段类型

编辑

point 数据类型有助于索引和搜索落在二维平面坐标系中的任意 x, y 对。

你可以使用Shape 查询来查询使用此类型的文档。

geo_shapegeo_point一样,point 可以以 GeoJSONWell-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 格式,具有 typecoordinates 键。

点以 Well-Known Text POINT 形式表示,格式为:"POINT(x y)"

点以对象形式表示,具有 xy 键。

点以数组形式表示,格式为:[x, y]

点以字符串形式表示,格式为:"x,y"

geo-point 字段类型的情况不同,对于以上所有格式,坐标 xy 的顺序是相同的。

提供给索引器的坐标是单精度浮点数值,因此该字段保证与 java 虚拟机提供的精度相同(通常为 1E-38)。

point 字段的参数

编辑

point 字段接受以下参数

ignore_malformed

如果为 true,则忽略格式不正确的点。如果为 false(默认值),则格式不正确的点会引发异常并拒绝整个文档。

ignore_z_value

如果为 true(默认值),则会接受三维点(存储在源中),但只会索引 x 和 y 值;第三维将被忽略。如果为 false,则包含多于 x 和 y(二维)值的点会引发异常并拒绝整个文档。

null_value

接受一个点值,该值将替换任何显式的 null 值。默认为 null,这意味着该字段被视为缺失。

排序和检索点

编辑

目前无法对点进行排序或直接检索其字段。point 值只能通过 _source 字段检索。