Create document with pre-defined geo_shapes in Elasticsearch
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
|
show 1 more comment
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
The real question is what do you need to do with those locations stored in your profiles index?
– Val
Nov 21 '18 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 '18 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
Nov 26 '18 at 10:56
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
Nov 26 '18 at 11:31
@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
Nov 26 '18 at 11:54
|
show 1 more comment
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 '18 at 13:24
Dan AndreassonDan Andreasson
5,45432025
5,45432025
The real question is what do you need to do with those locations stored in your profiles index?
– Val
Nov 21 '18 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 '18 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
Nov 26 '18 at 10:56
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
Nov 26 '18 at 11:31
@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
Nov 26 '18 at 11:54
|
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 '18 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 '18 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
Nov 26 '18 at 10:56
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
Nov 26 '18 at 11:31
@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
Nov 26 '18 at 11:54
The real question is what do you need to do with those locations stored in your profiles index?
– Val
Nov 21 '18 at 14:49
The real question is what do you need to do with those locations stored in your profiles index?
– Val
Nov 21 '18 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 '18 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 '18 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
Nov 26 '18 at 10:56
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
Nov 26 '18 at 10:56
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
Nov 26 '18 at 11:31
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
Nov 26 '18 at 11:31
@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
Nov 26 '18 at 11:54
@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
Nov 26 '18 at 11:54
|
show 1 more comment
1 Answer
1
active
oldest
votes
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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 Nov 26 '18 at 16:40
answered Nov 26 '18 at 11:58
ValVal
104k6141175
104k6141175
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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 '18 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 '18 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
Nov 26 '18 at 10:56
Okay, thanks for the suggestion, much appreciated!
– Dan Andreasson
Nov 26 '18 at 11:31
@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
Nov 26 '18 at 11:54