dosubot[bot] commented on issue #668: URL: https://github.com/apache/incubator-hugegraph-toolchain/issues/668#issuecomment-2934461790
<!-- Answer --> HugeGraph Java 客户端的 K-neighbor API 支持通过 POST 请求方式,对集合属性(如 set/list)进行条件过滤。你可以在 `Steps.StepEntity` 的 `properties` 字段中,使用字符串表达式(如 `P.within(...)` 或 `P.contains(...)`)来过滤集合属性,只要你的 schema 中该属性类型为 set 或 list。 下面是一个简单的 Java 示例,假设顶点有一个 set 类型的属性 `tags`,你想查找 tags 包含 "A" 或 "B" 的邻居: ```java import org.apache.hugegraph.api.traverser.KneighborAPI; import org.apache.hugegraph.structure.traverser.KneighborRequest; import org.apache.hugegraph.structure.traverser.Steps; import java.util.HashMap; import java.util.Map; // 构建属性过滤条件 Map<String, Object> properties = new HashMap<>(); properties.put("tags", "P.within(\"A\", \"B\")"); // 集合属性过滤 // 构建 StepEntity Steps.StepEntity vertexStep = new Steps.StepEntity("your_vertex_label", properties); // 构建 KneighborRequest KneighborRequest.Builder builder = KneighborRequest.builder(); builder.source("your_vertex_id"); builder.steps().direction(Direction.BOTH).vertexSteps(vertexStep); builder.maxDepth(1); builder.withVertex(true); KneighborRequest request = builder.build(); // 发起 K-neighbor 查询 KneighborAPI kneighborAPI = new KneighborAPI(client, "graphSpace", "graph"); Kneighbor result = kneighborAPI.post(request); ``` 核心点:`properties.put("tags", "P.within(\"A\", \"B\")")`,这样可以对 set/list 类型的属性进行过滤,语法与单值属性一致,HugeGraph 后端会自动识别集合类型并应用谓词。你也可以用 `P.contains("A")` 或其他 Gremlin 支持的谓词表达式。 官方文档和测试代码也有类似说明和用法,详见 [traverser.md](https://github.com/apache/incubator-hugegraph-doc/blob/f8b8bddd6123c2cf809ab69bba8c267ed02a7d67/content/en/docs/clients/restful-api/traverser.md) 和 [KneighborApiTest.java](https://github.com/apache/incubator-hugegraph-toolchain/blob/50a839469b1ad779115e371d0df378116638e9e1/hugegraph-client/src/test/java/org/apache/hugegraph/api/traverser/KneighborApiTest.java)。 如需更复杂的谓词或多层过滤,直接在 `properties` 里用字符串表达式即可,后端会解析并执行。 <!-- Dosu Comment Footer --> *To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/446eb84c-d027-4b19-94d7-2f6353c70271?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/446eb84c-d027-4b19-94d7-2f6353c70271?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/446eb84c-d027-4b19-94d7-2f6353c70271?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/446eb84c-d027-4b19-94d7-2f6353c70271?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/446eb84c-d027-4b19-94d7-2f6353c70271?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/446eb84c-d027-4b19-94d7-2f6353c70271?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/446eb84c-d027-4b19-94d7-2f6353c70271?feedback_type=other)</sup> [](https://go.dosu.dev/discord-bot) [! [Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/incubator-hugegraph-toolchain/issues/668) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@hugegraph.apache.org For additional commands, e-mail: issues-h...@hugegraph.apache.org