如何按属性排序

德里克·庞
2023-01-22 11:07

的AQL有一个限制wiki页面

限制
排序,限制而且抵消元素仅在以下情况下有效:

  • 您的查询没有包括元素
  • 如果你有包括元素,则只指定其中主域的字段。

例如,在下面的查询中,排序,限制而且抵消将不能工作,因为主域是,但包括元素中的字段构件、模块而且构建域应该显示:items.find()其中包括(“工件”、“artifact.module”,“artifact.module.build”)
这意味着,如果您搜索一个项目并包含该属性,您将无法根据该属性进行排序。items.find({“回购”:“example-repo-local”})。包括("repo","path", "name", "created", "@build.number")AQL参考体系结构

用户添加图片
虽然AQL不能直接按属性排序,但您可以使用外部工具解析返回的json并从中排序。

下面是一个使用jq实用程序的示例。$ curl -XPOST -uadmin "/artifactory/api/search/aql" -H "Content-Type: text/plain" -d 'items.find({"repo":"example-repo-local"})。包括(“回购”、“路径”、“名称”,“创建”、“@build.number”)“|金桥”。结果[]' | jq -s -c 'sort_by(.properties[0].value|tonumber) | reverse' | jq
示例响应:

“回购”:“example-repo-local”,
“路径”:“。”,
“名称”:“testtest.txt”,
“创建”:“2022 - 10 - 13 t18:32:44.644z”,
“属性”:[

“关键”:“build.number”,
“价值”:“十一”


},

“回购”:“example-repo-local”,
“路径”:“。”,
“名称”:“test2.txt”,
“创建”:“2022 - 10 - 13 t18:32:44.644z”,
“属性”:[

“关键”:“build.number”,
“价值”:“3”


},

“回购”:“example-repo-local”,
“路径”:“。”,
“名称”:“test1.txt”,
“创建”:“2022 - 10 - 13 t18:32:44.644z”,
“属性”:[

“关键”:“build.number”,
“价值”:“2”


},

“回购”:“example-repo-local”,
“路径”:“。”,
“名称”:“用法”,
“创建”:“2022 - 10 - 13 t18:32:44.644z”,
“属性”:[

“关键”:“build.number”,
“价值”:“1”