Azure Cosmos DB geospatial lookup consuming too high RU












1















I have a single Azure Cosmos DB collection I am querying against, hoping to use Geo-spatial index for efficient queries. The problem I'm encountering is that the RU consumption seems inefficient.



The collection has only 50k 1kb documents in it, but a query using ST_DISTANCE returning a single document consumes >900 RUs.



I've seen the RUs scale linearly based on the # of documents in the collection. It would seem indexing should prevent this behavior.



Example Query (950 RUs):



SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [34.69, -1.91] }) < 500


Example document:



[
{
"id": "1504891036",
"name": "Oujda",
"location": {
"type": "Point",
"coordinates": [
34.69,
-1.91
]
},
"population": 409391,
"country": "Morocco",
"country.iso2": "MA",
"country.iso3": "MAR",
}
]


I've not modified the default indexing policy, which seems to cover spatial indexing:



{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Spatial",
"dataType": "Point"
}
]
}
],
"excludedPaths":
}









share|improve this question























  • What is your partition key?

    – TeamTam
    Nov 28 '18 at 1:39











  • No partition key, just a fixed 10gb single partition of which only 68MB is being used.

    – rwrdb
    Nov 28 '18 at 2:55











  • Are you on the emulator or the real thing?

    – TeamTam
    Nov 28 '18 at 6:18











  • behavior is the same on both.

    – rwrdb
    Nov 30 '18 at 18:12











  • FWIW, I think either the index hasn't been applied properly or the query isn't using it when it runs. I have replicated a dataset similar to yours. When I query using the index, my RU stays constant below 10. However, when I deliberately avoid the index I get ~1000RU.

    – TeamTam
    Nov 30 '18 at 23:20
















1















I have a single Azure Cosmos DB collection I am querying against, hoping to use Geo-spatial index for efficient queries. The problem I'm encountering is that the RU consumption seems inefficient.



The collection has only 50k 1kb documents in it, but a query using ST_DISTANCE returning a single document consumes >900 RUs.



I've seen the RUs scale linearly based on the # of documents in the collection. It would seem indexing should prevent this behavior.



Example Query (950 RUs):



SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [34.69, -1.91] }) < 500


Example document:



[
{
"id": "1504891036",
"name": "Oujda",
"location": {
"type": "Point",
"coordinates": [
34.69,
-1.91
]
},
"population": 409391,
"country": "Morocco",
"country.iso2": "MA",
"country.iso3": "MAR",
}
]


I've not modified the default indexing policy, which seems to cover spatial indexing:



{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Spatial",
"dataType": "Point"
}
]
}
],
"excludedPaths":
}









share|improve this question























  • What is your partition key?

    – TeamTam
    Nov 28 '18 at 1:39











  • No partition key, just a fixed 10gb single partition of which only 68MB is being used.

    – rwrdb
    Nov 28 '18 at 2:55











  • Are you on the emulator or the real thing?

    – TeamTam
    Nov 28 '18 at 6:18











  • behavior is the same on both.

    – rwrdb
    Nov 30 '18 at 18:12











  • FWIW, I think either the index hasn't been applied properly or the query isn't using it when it runs. I have replicated a dataset similar to yours. When I query using the index, my RU stays constant below 10. However, when I deliberately avoid the index I get ~1000RU.

    – TeamTam
    Nov 30 '18 at 23:20














1












1








1


1






I have a single Azure Cosmos DB collection I am querying against, hoping to use Geo-spatial index for efficient queries. The problem I'm encountering is that the RU consumption seems inefficient.



The collection has only 50k 1kb documents in it, but a query using ST_DISTANCE returning a single document consumes >900 RUs.



I've seen the RUs scale linearly based on the # of documents in the collection. It would seem indexing should prevent this behavior.



Example Query (950 RUs):



SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [34.69, -1.91] }) < 500


Example document:



[
{
"id": "1504891036",
"name": "Oujda",
"location": {
"type": "Point",
"coordinates": [
34.69,
-1.91
]
},
"population": 409391,
"country": "Morocco",
"country.iso2": "MA",
"country.iso3": "MAR",
}
]


I've not modified the default indexing policy, which seems to cover spatial indexing:



{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Spatial",
"dataType": "Point"
}
]
}
],
"excludedPaths":
}









share|improve this question














I have a single Azure Cosmos DB collection I am querying against, hoping to use Geo-spatial index for efficient queries. The problem I'm encountering is that the RU consumption seems inefficient.



The collection has only 50k 1kb documents in it, but a query using ST_DISTANCE returning a single document consumes >900 RUs.



I've seen the RUs scale linearly based on the # of documents in the collection. It would seem indexing should prevent this behavior.



Example Query (950 RUs):



SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [34.69, -1.91] }) < 500


Example document:



[
{
"id": "1504891036",
"name": "Oujda",
"location": {
"type": "Point",
"coordinates": [
34.69,
-1.91
]
},
"population": 409391,
"country": "Morocco",
"country.iso2": "MA",
"country.iso3": "MAR",
}
]


I've not modified the default indexing policy, which seems to cover spatial indexing:



{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Range",
"dataType": "String",
"precision": -1
},
{
"kind": "Spatial",
"dataType": "Point"
}
]
}
],
"excludedPaths":
}






azure azure-cosmosdb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 19:25









rwrdbrwrdb

1084




1084













  • What is your partition key?

    – TeamTam
    Nov 28 '18 at 1:39











  • No partition key, just a fixed 10gb single partition of which only 68MB is being used.

    – rwrdb
    Nov 28 '18 at 2:55











  • Are you on the emulator or the real thing?

    – TeamTam
    Nov 28 '18 at 6:18











  • behavior is the same on both.

    – rwrdb
    Nov 30 '18 at 18:12











  • FWIW, I think either the index hasn't been applied properly or the query isn't using it when it runs. I have replicated a dataset similar to yours. When I query using the index, my RU stays constant below 10. However, when I deliberately avoid the index I get ~1000RU.

    – TeamTam
    Nov 30 '18 at 23:20



















  • What is your partition key?

    – TeamTam
    Nov 28 '18 at 1:39











  • No partition key, just a fixed 10gb single partition of which only 68MB is being used.

    – rwrdb
    Nov 28 '18 at 2:55











  • Are you on the emulator or the real thing?

    – TeamTam
    Nov 28 '18 at 6:18











  • behavior is the same on both.

    – rwrdb
    Nov 30 '18 at 18:12











  • FWIW, I think either the index hasn't been applied properly or the query isn't using it when it runs. I have replicated a dataset similar to yours. When I query using the index, my RU stays constant below 10. However, when I deliberately avoid the index I get ~1000RU.

    – TeamTam
    Nov 30 '18 at 23:20

















What is your partition key?

– TeamTam
Nov 28 '18 at 1:39





What is your partition key?

– TeamTam
Nov 28 '18 at 1:39













No partition key, just a fixed 10gb single partition of which only 68MB is being used.

– rwrdb
Nov 28 '18 at 2:55





No partition key, just a fixed 10gb single partition of which only 68MB is being used.

– rwrdb
Nov 28 '18 at 2:55













Are you on the emulator or the real thing?

– TeamTam
Nov 28 '18 at 6:18





Are you on the emulator or the real thing?

– TeamTam
Nov 28 '18 at 6:18













behavior is the same on both.

– rwrdb
Nov 30 '18 at 18:12





behavior is the same on both.

– rwrdb
Nov 30 '18 at 18:12













FWIW, I think either the index hasn't been applied properly or the query isn't using it when it runs. I have replicated a dataset similar to yours. When I query using the index, my RU stays constant below 10. However, when I deliberately avoid the index I get ~1000RU.

– TeamTam
Nov 30 '18 at 23:20





FWIW, I think either the index hasn't been applied properly or the query isn't using it when it runs. I have replicated a dataset similar to yours. When I query using the index, my RU stays constant below 10. However, when I deliberately avoid the index I get ~1000RU.

– TeamTam
Nov 30 '18 at 23:20












1 Answer
1






active

oldest

votes


















0














I determined the problem. I had transposed the longitude and the latitude coordinate prescribed by GeoJSON:



Cosmos is expecting:



"location": {
"type": "Point",
"coordinates": [
<@lon>,
<@lat>
]


I had assumed, incorrectly, that it was lat/lon. Therefore many of my latitudes were outside of the 90/-90 range required, since longitude can be 180/-180. After re-creating my ~50k documents, RU for coordinate based lookups are consistently <10 RUs.



Before fix (all docs have transposed lat/lon coordinates, many outside the 90/-90 bounds and therefore invalid):



SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [34.69, -1.91] }) < 500
940 RUs, 1 document returned


After fix (all docs re-created with lat/lon set correctly per GeoJSON specs):



SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [-1.91,34.69] }) < 500
6 RUs, 1 document returned


Initial issue was confirmed/diagnosed by the following query:



SELECT ST_ISVALIDDETAILED(c.location) FROM c where c.name = "Kansas City"
Error: "Latitude values must be between -90 and 90 degrees."





share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419240%2fazure-cosmos-db-geospatial-lookup-consuming-too-high-ru%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









    0














    I determined the problem. I had transposed the longitude and the latitude coordinate prescribed by GeoJSON:



    Cosmos is expecting:



    "location": {
    "type": "Point",
    "coordinates": [
    <@lon>,
    <@lat>
    ]


    I had assumed, incorrectly, that it was lat/lon. Therefore many of my latitudes were outside of the 90/-90 range required, since longitude can be 180/-180. After re-creating my ~50k documents, RU for coordinate based lookups are consistently <10 RUs.



    Before fix (all docs have transposed lat/lon coordinates, many outside the 90/-90 bounds and therefore invalid):



    SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [34.69, -1.91] }) < 500
    940 RUs, 1 document returned


    After fix (all docs re-created with lat/lon set correctly per GeoJSON specs):



    SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [-1.91,34.69] }) < 500
    6 RUs, 1 document returned


    Initial issue was confirmed/diagnosed by the following query:



    SELECT ST_ISVALIDDETAILED(c.location) FROM c where c.name = "Kansas City"
    Error: "Latitude values must be between -90 and 90 degrees."





    share|improve this answer




























      0














      I determined the problem. I had transposed the longitude and the latitude coordinate prescribed by GeoJSON:



      Cosmos is expecting:



      "location": {
      "type": "Point",
      "coordinates": [
      <@lon>,
      <@lat>
      ]


      I had assumed, incorrectly, that it was lat/lon. Therefore many of my latitudes were outside of the 90/-90 range required, since longitude can be 180/-180. After re-creating my ~50k documents, RU for coordinate based lookups are consistently <10 RUs.



      Before fix (all docs have transposed lat/lon coordinates, many outside the 90/-90 bounds and therefore invalid):



      SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [34.69, -1.91] }) < 500
      940 RUs, 1 document returned


      After fix (all docs re-created with lat/lon set correctly per GeoJSON specs):



      SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [-1.91,34.69] }) < 500
      6 RUs, 1 document returned


      Initial issue was confirmed/diagnosed by the following query:



      SELECT ST_ISVALIDDETAILED(c.location) FROM c where c.name = "Kansas City"
      Error: "Latitude values must be between -90 and 90 degrees."





      share|improve this answer


























        0












        0








        0







        I determined the problem. I had transposed the longitude and the latitude coordinate prescribed by GeoJSON:



        Cosmos is expecting:



        "location": {
        "type": "Point",
        "coordinates": [
        <@lon>,
        <@lat>
        ]


        I had assumed, incorrectly, that it was lat/lon. Therefore many of my latitudes were outside of the 90/-90 range required, since longitude can be 180/-180. After re-creating my ~50k documents, RU for coordinate based lookups are consistently <10 RUs.



        Before fix (all docs have transposed lat/lon coordinates, many outside the 90/-90 bounds and therefore invalid):



        SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [34.69, -1.91] }) < 500
        940 RUs, 1 document returned


        After fix (all docs re-created with lat/lon set correctly per GeoJSON specs):



        SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [-1.91,34.69] }) < 500
        6 RUs, 1 document returned


        Initial issue was confirmed/diagnosed by the following query:



        SELECT ST_ISVALIDDETAILED(c.location) FROM c where c.name = "Kansas City"
        Error: "Latitude values must be between -90 and 90 degrees."





        share|improve this answer













        I determined the problem. I had transposed the longitude and the latitude coordinate prescribed by GeoJSON:



        Cosmos is expecting:



        "location": {
        "type": "Point",
        "coordinates": [
        <@lon>,
        <@lat>
        ]


        I had assumed, incorrectly, that it was lat/lon. Therefore many of my latitudes were outside of the 90/-90 range required, since longitude can be 180/-180. After re-creating my ~50k documents, RU for coordinate based lookups are consistently <10 RUs.



        Before fix (all docs have transposed lat/lon coordinates, many outside the 90/-90 bounds and therefore invalid):



        SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [34.69, -1.91] }) < 500
        940 RUs, 1 document returned


        After fix (all docs re-created with lat/lon set correctly per GeoJSON specs):



        SELECT * FROM c where ST_DISTANCE(c.location, { 'type': 'Point', 'coordinates': [-1.91,34.69] }) < 500
        6 RUs, 1 document returned


        Initial issue was confirmed/diagnosed by the following query:



        SELECT ST_ISVALIDDETAILED(c.location) FROM c where c.name = "Kansas City"
        Error: "Latitude values must be between -90 and 90 degrees."






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 6 '18 at 0:59









        rwrdbrwrdb

        1084




        1084
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419240%2fazure-cosmos-db-geospatial-lookup-consuming-too-high-ru%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

            Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

            A Topological Invariant for $pi_3(U(n))$