简体   繁体   English

问:Azure Cosmos DB Graph:当索引策略定义为手动时,如何在Graph API中运行查询?

[英]Q: Azure Cosmos DB Graph: How to run queries in Graph API when Indexing Policy is defined as Manual?

In Cosmos DB graph when I am defining Indexing policy as Automatic, I am able to run queries but when I am updating indexing policy to Manual and defining Indexing path (/label/?) and Indexing mode set as 'Consistent', the query is not fetching any data. 在Cosmos DB图中,当我将索引策略定义为自动时,我能够运行查询但是当我将索引策略更新为手动并定义索引路径(/ label /?)并将索引模式设置为'Consistent'时,查询是没有提取任何数据。

Let's say my first query (when Indexing policy set as Manual) is : 假设我的第一个查询(当索引策略设置为手动时)是:

g.addV('Azure').property('name','Cerulean Software'))

Result is : 结果是:

[
    {
        "id": "0c14a00a-edf6-46b1-9e40-45cc37f750ea",
        "label": "Azure",
        "type": "vertex",
        "properties": {
            "name": [
                {
                    "id": "f89ee2ee-74df-4256-a5d4-2b47eb526976",
                    "value": "Cerulean Software"
                }
            ]
        }
    }
]

Now, my second query (when Indexing policy set as Manual (see Edit #1 below)) is: 现在,我的第二个查询(当索引策略设置为手动(参见下面的编辑#1))是:

g.V().hasLabel('Azure')

This second query is not fetching any result even though there is vertex present in graph named as 'Azure'. 即使在名为“Azure”的图形中存在顶点,第二个查询也不会获取任何结果。

What could be the possible reason behind this? 这背后可能的原因是什么?

Edit #1: Manual Indexing Policy Before Change 编辑#1:更改前的手动索引策略

"indexingPolicy": {
    "automatic": false,
    "excludedPaths": [],
    "includedPaths": [
        {
            "path": "/*",
            "indexes": [
                {
                    "dataType": "Number",
                    "kind": "Range",
                    "precision": -1
                },
                {
                    "dataType": "String",
                    "kind": "Hash",
                    "precision": 3
                }
            ]
        },
        {
            "path": "/label/?",
            "indexes": [
                {
                    "dataType": "String",
                    "kind": "Hash",
                    "precision": 3
                },
                {
                    "dataType": "Number",
                    "kind": "Range",
                    "precision": -1
                }
            ]
        }
    ],
    "indexingMode": "consistent"
},

Edit #2: Manual Indexing Policy After Change 编辑#2:更改后的手动索引策略

"indexingPolicy": {
    "automatic": false,
    "excludedPaths": [],
    "includedPaths": [
        {
            "path": "/*",
            "indexes": [
                {
                    "dataType": "Number",
                    "kind": "Range",
                    "precision": -1
                },
                {
                    "dataType": "String",
                    "kind": "Hash",
                    "precision": 3
                }
            ]
        },
        {
            "path": "/_isEdge/?",
            "indexes": [
                {
                    "dataType": "String",
                    "kind": "Hash",
                    "precision": 3
                },
                {
                    "dataType": "Number",
                    "kind": "Range",
                    "precision": -1
                }
            ]
        }
    ],
    "indexingMode": "consistent"
},

With Cosmos, graph statements are not executed as traversals on the Azure side. 使用Cosmos,图形语句不会作为Azure端的遍历执行。 The graph client actually translates gremlin statements into Document SQL calls and then aggregates the results back to you on the client side. 图形客户端实际上将gremlin语句转换为Document SQL调用,然后在客户端将结果聚合回给您。 In the case of your statement gV().hasLabel('Azure') the call is actually translated to {"query":"SELECT N_2 FROM Node N_2 WHERE (IS_DEFINED(N_2._isEdge) = false AND (N_2.label = 'Azure'))"} 在您的语句gV().hasLabel('Azure')的情况下,该调用实际上被转换为{"query":"SELECT N_2 FROM Node N_2 WHERE (IS_DEFINED(N_2._isEdge) = false AND (N_2.label = 'Azure'))"}

This can be verified through the use of a proxy such as Fiddler which will allow you to inspect the outbound calls from your machine. 这可以通过使用Fiddler等代理进行验证,这样您就可以检查机器的出站呼叫。

The top level _isEdge property seems to be used across almost all Gremlin translated queries so I suspect that if you add that property to your indexing policy you should start to see the expected results. 顶级_isEdge属性似乎用于几乎所有Gremlin翻译的查询,所以我怀疑如果你将该属性添加到索引策略,你应该开始看到预期的结果。

EDIT: I originally missed the part of your indexing policy that sets automatic: false . 编辑:我最初错过了automatic: false设置索引策略的部分automatic: false According to the Cosmos docs (under the heading Opting in and opting out of indexing ), By default, all documents are automatically indexed, but you can choose to turn it off. When indexing is turned off, documents can be accessed only through their self-links or by queries using ID. 根据Cosmos文档 (在Opting in and opting out of indexing标题下), By default, all documents are automatically indexed, but you can choose to turn it off. When indexing is turned off, documents can be accessed only through their self-links or by queries using ID. By default, all documents are automatically indexed, but you can choose to turn it off. When indexing is turned off, documents can be accessed only through their self-links or by queries using ID.

If you choose to run with indexing turned off, then the rest of your indexing policy is effectively meaningless and queries that aren't directly by document Id will no longer work. 如果您选择在关闭索引的情况下运行,那么索引策略的其余部分实际上毫无意义,并且不直接由文档ID进行的查询将不再起作用。 Can you elaborate as to what you're actually trying to accomplish here? 你能详细说明你在这里想要实现的目标吗? There seems to be a bit of confusion. 似乎有点混乱。 The indexing settings you've placed on label and isEdge aren't even necessary because they are the same as the value you've put for * which is the default rule matching all paths. 您放置在labelisEdge上的索引设置甚至不是必需的,因为它们与您为*放置的值相同*这是与所有路径匹配的默认规则。

Post what your goals are for your indexing strategy and I can try to make an appropriate recommendation but you're definitely going to want to put automatic: true back into your policy. 发布您的索引策略的目标是什么,我可以尝试做出适当的推荐,但您肯定会想要automatic: true回到您的策略中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM