Point field type
Point field type
The point
data type facilitates the indexing of and searching arbitrary x, y
pairs that fall in a 2-dimensional planar coordinate system.
You can query documents using this type using shape Query.
As with geo_shape and geo_point, point
can be specified in GeoJSON and Well-Known Text formats. However, there are a number of additional formats that are supported for convenience and historical reasons. In total there are five ways that a cartesian point may be specified, as demonstrated below:
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"
}
Point expressed as an object, in GeoJSON format, with | |
Point expressed as a Well-Known Text POINT with the format: | |
Point expressed as an object, with | |
Point expressed as an array with the format: [ | |
Point expressed as a string with the format: |
Unlike the case with the geo-point field type, the order of the coordinates x
and y
is the same for all formats above.
The coordinates provided to the indexer are single precision floating point values so the field guarantees the same accuracy provided by the java virtual machine (typically 1E-38
).
Parameters for point
fields
The following parameters are accepted by point
fields:
If | |
| If |
Accepts an point value which is substituted for any explicit |
Sorting and retrieving points
It is currently not possible to sort points or retrieve their fields directly. The point
value is only retrievable through the _source
field.