Create document with pre-defined geo_shapes in Elasticsearch
up vote
0
down vote
favorite
I have two indices:
- Profiles - Has a field which is an array of
geo_shape
- Locations - Has a field geometry which is a
geo_shape
Each document in profiles has many locations. Currently, a copy of locations' geometry is stored in profile documents.
Is it possible to improve this by creating a profile document with pre-defined geo_shapes
? I've tried
PUT profiles/profile/1
{
"locations": [
{
"indexed_shape": {
"id": "LOC1",
"index": "locations",
"path": "geometry",
"type": "location"
}
},
{
"indexed_shape": {
"id": "LOC2",
"index": "locations",
"path": "geometry",
"type": "location"
}
}
]
}
which is much like the query syntax for pre-defined geo shapes, but to no avail. I can't find anything in the docs. Is there a solution to this problem, or do I have to manage copies?
elasticsearch gis
This question has an open bounty worth +100
reputation from Dan Andreasson ending in 6 days.
This question has not received enough attention.
|
show 1 more comment
up vote
0
down vote
favorite
I have two indices:
- Profiles - Has a field which is an array of
geo_shape
- Locations - Has a field geometry which is a
geo_shape
Each document in profiles has many locations. Currently, a copy of locations' geometry is stored in profile documents.
Is it possible to improve this by creating a profile document with pre-defined geo_shapes
? I've tried
PUT profiles/profile/1
{
"locations": [
{
"indexed_shape": {
"id": "LOC1",
"index": "locations",
"path": "geometry",
"type": "location"
}
},
{
"indexed_shape": {
"id": "LOC2",
"index": "locations",
"path": "geometry",
"type": "location"
}
}
]
}
which is much like the query syntax for pre-defined geo shapes, but to no avail. I can't find anything in the docs. Is there a solution to this problem, or do I have to manage copies?
elasticsearch gis
This question has an open bounty worth +100
reputation from Dan Andreasson ending in 6 days.
This question has not received enough attention.
The real question is what do you need to do with those locations stored in your profiles index?
– Val
Nov 21 at 14:49
@Val This is a simplified example, but I need to both search for profiles which have overlapping polygons (geo_shape really, could be geo collection) or contains a point. I've thought about having a separate index calledprofile_locations
which mirrors my Postgres table. Not sure if that makes more sense? Still, have the same problem with managing copies tho
– Dan Andreasson
Nov 21 at 14:55
1
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in thelocations
array in theprofiles
index. Then when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.
– Val
18 hours ago
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
17 hours ago
@Val a quick question. What about when I want to search for profiles within a polygon and other criteria that lives on the profile? Is that somehow possible if I introduce aprofile_locations
index?
– Dan Andreasson
17 hours ago
|
show 1 more comment
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have two indices:
- Profiles - Has a field which is an array of
geo_shape
- Locations - Has a field geometry which is a
geo_shape
Each document in profiles has many locations. Currently, a copy of locations' geometry is stored in profile documents.
Is it possible to improve this by creating a profile document with pre-defined geo_shapes
? I've tried
PUT profiles/profile/1
{
"locations": [
{
"indexed_shape": {
"id": "LOC1",
"index": "locations",
"path": "geometry",
"type": "location"
}
},
{
"indexed_shape": {
"id": "LOC2",
"index": "locations",
"path": "geometry",
"type": "location"
}
}
]
}
which is much like the query syntax for pre-defined geo shapes, but to no avail. I can't find anything in the docs. Is there a solution to this problem, or do I have to manage copies?
elasticsearch gis
I have two indices:
- Profiles - Has a field which is an array of
geo_shape
- Locations - Has a field geometry which is a
geo_shape
Each document in profiles has many locations. Currently, a copy of locations' geometry is stored in profile documents.
Is it possible to improve this by creating a profile document with pre-defined geo_shapes
? I've tried
PUT profiles/profile/1
{
"locations": [
{
"indexed_shape": {
"id": "LOC1",
"index": "locations",
"path": "geometry",
"type": "location"
}
},
{
"indexed_shape": {
"id": "LOC2",
"index": "locations",
"path": "geometry",
"type": "location"
}
}
]
}
which is much like the query syntax for pre-defined geo shapes, but to no avail. I can't find anything in the docs. Is there a solution to this problem, or do I have to manage copies?
elasticsearch gis
elasticsearch gis
asked Nov 21 at 13:24
Dan Andreasson
5,03831924
5,03831924
This question has an open bounty worth +100
reputation from Dan Andreasson ending in 6 days.
This question has not received enough attention.
This question has an open bounty worth +100
reputation from Dan Andreasson ending in 6 days.
This question has not received enough attention.
The real question is what do you need to do with those locations stored in your profiles index?
– Val
Nov 21 at 14:49
@Val This is a simplified example, but I need to both search for profiles which have overlapping polygons (geo_shape really, could be geo collection) or contains a point. I've thought about having a separate index calledprofile_locations
which mirrors my Postgres table. Not sure if that makes more sense? Still, have the same problem with managing copies tho
– Dan Andreasson
Nov 21 at 14:55
1
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in thelocations
array in theprofiles
index. Then when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.
– Val
18 hours ago
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
17 hours ago
@Val a quick question. What about when I want to search for profiles within a polygon and other criteria that lives on the profile? Is that somehow possible if I introduce aprofile_locations
index?
– Dan Andreasson
17 hours ago
|
show 1 more comment
The real question is what do you need to do with those locations stored in your profiles index?
– Val
Nov 21 at 14:49
@Val This is a simplified example, but I need to both search for profiles which have overlapping polygons (geo_shape really, could be geo collection) or contains a point. I've thought about having a separate index calledprofile_locations
which mirrors my Postgres table. Not sure if that makes more sense? Still, have the same problem with managing copies tho
– Dan Andreasson
Nov 21 at 14:55
1
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in thelocations
array in theprofiles
index. Then when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.
– Val
18 hours ago
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
17 hours ago
@Val a quick question. What about when I want to search for profiles within a polygon and other criteria that lives on the profile? Is that somehow possible if I introduce aprofile_locations
index?
– Dan Andreasson
17 hours ago
The real question is what do you need to do with those locations stored in your profiles index?
– Val
Nov 21 at 14:49
The real question is what do you need to do with those locations stored in your profiles index?
– Val
Nov 21 at 14:49
@Val This is a simplified example, but I need to both search for profiles which have overlapping polygons (geo_shape really, could be geo collection) or contains a point. I've thought about having a separate index called
profile_locations
which mirrors my Postgres table. Not sure if that makes more sense? Still, have the same problem with managing copies tho– Dan Andreasson
Nov 21 at 14:55
@Val This is a simplified example, but I need to both search for profiles which have overlapping polygons (geo_shape really, could be geo collection) or contains a point. I've thought about having a separate index called
profile_locations
which mirrors my Postgres table. Not sure if that makes more sense? Still, have the same problem with managing copies tho– Dan Andreasson
Nov 21 at 14:55
1
1
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in the
locations
array in the profiles
index. Then when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.– Val
18 hours ago
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in the
locations
array in the profiles
index. Then when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.– Val
18 hours ago
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
17 hours ago
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
17 hours ago
@Val a quick question. What about when I want to search for profiles within a polygon and other criteria that lives on the profile? Is that somehow possible if I introduce a
profile_locations
index?– Dan Andreasson
17 hours ago
@Val a quick question. What about when I want to search for profiles within a polygon and other criteria that lives on the profile? Is that somehow possible if I introduce a
profile_locations
index?– Dan Andreasson
17 hours ago
|
show 1 more comment
1 Answer
1
active
oldest
votes
up vote
1
down vote
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in the locations array in the profiles index, like this:
PUT shapes/doc/LOC1
{
... shape definition goes here ...
}
PUT shapes/doc/LOC2
{
... shape definition goes here ...
}
PUT profiles/doc/1
{
"locations": [ "LOC1", "LOC2" ]
... other fields
}
Then, when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.
First, query the shapes and gather the ids:
POST shapes/_search?filter_path=hits.hits._id
{
"query" : {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
=> returns "LOC1", "LOC3", "LOC4"
Finally, query the profiles index
POST profiles/_search
{
"query": {
"bool": {
"filter": [
{
...other profile criteria go here...
},
{
"terms": {
"locations": ["LOC1", "LOC3", "LOC4" ]
}
}
]
}
}
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in the locations array in the profiles index, like this:
PUT shapes/doc/LOC1
{
... shape definition goes here ...
}
PUT shapes/doc/LOC2
{
... shape definition goes here ...
}
PUT profiles/doc/1
{
"locations": [ "LOC1", "LOC2" ]
... other fields
}
Then, when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.
First, query the shapes and gather the ids:
POST shapes/_search?filter_path=hits.hits._id
{
"query" : {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
=> returns "LOC1", "LOC3", "LOC4"
Finally, query the profiles index
POST profiles/_search
{
"query": {
"bool": {
"filter": [
{
...other profile criteria go here...
},
{
"terms": {
"locations": ["LOC1", "LOC3", "LOC4" ]
}
}
]
}
}
}
add a comment |
up vote
1
down vote
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in the locations array in the profiles index, like this:
PUT shapes/doc/LOC1
{
... shape definition goes here ...
}
PUT shapes/doc/LOC2
{
... shape definition goes here ...
}
PUT profiles/doc/1
{
"locations": [ "LOC1", "LOC2" ]
... other fields
}
Then, when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.
First, query the shapes and gather the ids:
POST shapes/_search?filter_path=hits.hits._id
{
"query" : {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
=> returns "LOC1", "LOC3", "LOC4"
Finally, query the profiles index
POST profiles/_search
{
"query": {
"bool": {
"filter": [
{
...other profile criteria go here...
},
{
"terms": {
"locations": ["LOC1", "LOC3", "LOC4" ]
}
}
]
}
}
}
add a comment |
up vote
1
down vote
up vote
1
down vote
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in the locations array in the profiles index, like this:
PUT shapes/doc/LOC1
{
... shape definition goes here ...
}
PUT shapes/doc/LOC2
{
... shape definition goes here ...
}
PUT profiles/doc/1
{
"locations": [ "LOC1", "LOC2" ]
... other fields
}
Then, when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.
First, query the shapes and gather the ids:
POST shapes/_search?filter_path=hits.hits._id
{
"query" : {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
=> returns "LOC1", "LOC3", "LOC4"
Finally, query the profiles index
POST profiles/_search
{
"query": {
"bool": {
"filter": [
{
...other profile criteria go here...
},
{
"terms": {
"locations": ["LOC1", "LOC3", "LOC4" ]
}
}
]
}
}
}
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in the locations array in the profiles index, like this:
PUT shapes/doc/LOC1
{
... shape definition goes here ...
}
PUT shapes/doc/LOC2
{
... shape definition goes here ...
}
PUT profiles/doc/1
{
"locations": [ "LOC1", "LOC2" ]
... other fields
}
Then, when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.
First, query the shapes and gather the ids:
POST shapes/_search?filter_path=hits.hits._id
{
"query" : {
"geo_shape": {
"location": {
"shape": {
"type": "envelope",
"coordinates" : [[13.0, 53.0], [14.0, 52.0]]
},
"relation": "within"
}
}
}
}
=> returns "LOC1", "LOC3", "LOC4"
Finally, query the profiles index
POST profiles/_search
{
"query": {
"bool": {
"filter": [
{
...other profile criteria go here...
},
{
"terms": {
"locations": ["LOC1", "LOC3", "LOC4" ]
}
}
]
}
}
}
edited 12 hours ago
answered 17 hours ago
Val
98.5k6125163
98.5k6125163
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413042%2fcreate-document-with-pre-defined-geo-shapes-in-elasticsearch%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The real question is what do you need to do with those locations stored in your profiles index?
– Val
Nov 21 at 14:49
@Val This is a simplified example, but I need to both search for profiles which have overlapping polygons (geo_shape really, could be geo collection) or contains a point. I've thought about having a separate index called
profile_locations
which mirrors my Postgres table. Not sure if that makes more sense? Still, have the same problem with managing copies tho– Dan Andreasson
Nov 21 at 14:55
1
Unfortunately, there is no way (yet) to store references to indexed shapes. What you could do is to pre-index shapes into a dedicated index and then store the IDs of those shapes in the
locations
array in theprofiles
index. Then when you need to query, you can first do the query on the shapes index, gather the ids of the matching shapes and then query the profiles index using those ids. I don't see a way to make it shorter than that.– Val
18 hours ago
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
17 hours ago
@Val a quick question. What about when I want to search for profiles within a polygon and other criteria that lives on the profile? Is that somehow possible if I introduce a
profile_locations
index?– Dan Andreasson
17 hours ago