0

我有像我附上的那个json。如果processorMap.id 符合条件,我想读取processorMap 下的id。例如,如果我搜索值“为 mongo 设置值”,那么我应该得到 => 1c9b2d18-e9ab-3512-803a-c1ee5f7a2793

$.processorMap[?(@.name=='set value for mongo')]我在https://jsonpath.com/中测试了我的 JSON 和模式,但是在 nifi 中我什么也没得到。我试过了,“EvaluateJsonPath”处理器下的所有组合。

在这里需要一些帮助。

{
  "id": "15d85c21-0171-1000-ffff-ffffe6fe5d3b",
  "name": "metadata",
  "parentGroupId": "15d85c04-0171-1000-ffff-ffffd3ad29ed",
  "parentGroupName": "trax_ga",
  "feedName": "trax_ga.metadata",
  "processorMap": {
    "c0da50c1-b7be-3f30-8a20-dd3fcd8a853e": {
      "id": "c0da50c1-b7be-3f30-8a20-dd3fcd8a853e",
      "name": "RouteOnAttribute",
      "type": "org.apache.nifi.processors.standard.RouteOnAttribute",
      "parentGroupId": "fbf7c26f-ccc6-3b11-b581-3a0b4f806ee2",
      "flowId": null,
      "processGroup": null,
      "sourceIds": [
        "bb0b5816-7277-353d-ab1c-342b29d8b048"
      ],
      "destinationIds": [
        "3fc9028e-8423-3f7a-ba72-4798bff4e4ed",
        "4b508332-edc1-3354-883b-df689f9569a3"
      ],
      "sourceConnectionIds": [
        {
          "connectionIdentifier": "6e9e5cc0-a254-3bd8-ac63-8de6c58466b1",
          "name": "",
          "selectedRelationships": [
            "error"
          ]
        },
        {
          "connectionIdentifier": "dac2abc4-01fa-38df-a415-846b8dc92299",
          "name": "",
          "selectedRelationships": []
        }
      ],
      "destinationConnectionIds": [
        {
          "connectionIdentifier": "1895712a-20e0-3817-a51a-85f1086cb9ec",
          "name": "",
          "selectedRelationships": [
            "invoke_fail_counter_check"
          ]
        },
        {
          "connectionIdentifier": "65101e1a-4272-3d6a-9be8-282a07204608",
          "name": "",
          "selectedRelationships": [
            "unmatched"
          ]
        }
      ],
      "allDestinationIds": [
        "3fc9028e-8423-3f7a-ba72-4798bff4e4ed",
        "4b508332-edc1-3354-883b-df689f9569a3"
      ],
      "sortedDestinations": [],
      "leaf": false,
      "start": false,
      "end": false
    },
    "1c9b2d18-e9ab-3512-803a-c1ee5f7a2793": {
      "id": "1c9b2d18-e9ab-3512-803a-c1ee5f7a2793",
      "name": "set value for mongo",
      "type": "org.apache.nifi.processors.attributes.UpdateAttribute",
      "parentGroupId": "f12c169c-016e-1000-0000-00006edfe223",
      "flowId": null,
      "processGroup": null,
      "sourceIds": [
        "62af07df-8c70-3b9b-9b0d-dbaa57431ffc"
      ],
      "destinationIds": [
        "a84c0c13-2071-3bef-834d-9b415a3753fd"
      ],
      "sourceConnectionIds": [
        {
          "connectionIdentifier": "bb31af1f-e5b7-3300-913a-d51fcc5adc01",
          "name": "",
          "selectedRelationships": [
            "success"
          ]
        }
      ],
      "destinationConnectionIds": [
        {
          "connectionIdentifier": "f8e8ed08-179b-316d-8755-710d2e0f597e",
          "name": "",
          "selectedRelationships": []
        },
        {
          "connectionIdentifier": "63dda8ed-33d6-3ad2-ab0d-f50b156eecdf",
          "name": "",
          "selectedRelationships": [
            "success"
          ]
        }
      ],
      "allDestinationIds": [
        "a84c0c13-2071-3bef-834d-9b415a3753fd"
      ],
      "sortedDestinations": [],
      "leaf": false,
      "start": false,
      "end": false
    },
    "c1563452-eb9d-38eb-9599-f39681b22d94": {
      "id": "c1563452-eb9d-38eb-9599-f39681b22d94",
      "name": "Check for timeout error",
      "type": "org.apache.nifi.processors.standard.RouteOnAttribute",
      "parentGroupId": "f12c169c-016e-1000-0000-00006edfe223",
      "flowId": "72__RouteOnAttribute",
      "processGroup": null,
      "sourceIds": [
        "eb42f7bf-c3df-3284-9ebf-1fafd9971089",
        "a637159c-db7a-3909-b4e2-b17f8b77c492",
        "12835bbc-06b9-3d5c-bb69-354fbfb54ce0",
        "5f5bffc7-ede1-3d8e-a950-4aac3127cd61"
      ],
      "destinationIds": [
        "0d2c922d-c4a3-3b0f-bc98-d4e6aef2c98a",
        "382d3d98-85f7-3eaf-a124-c6845687a5fa"
      ],
      "sourceConnectionIds": [
        {
          "connectionIdentifier": "a01ca658-00c4-3215-a7f5-3891207ca15a",
          "name": "",
          "selectedRelationships": []
        },
        {
          "connectionIdentifier": "af49fb56-c970-3992-8c27-3b69cb8a96a3",
          "name": "",
          "selectedRelationships": []
        },
        {
          "connectionIdentifier": "6d16cf04-00da-3986-a7e7-72af219e7116",
          "name": "",
          "selectedRelationships": [
            "failure"
          ]
        },
        {
          "connectionIdentifier": "e943d2fa-bddb-33f3-8e1f-73663e32957a",
          "name": "",
          "selectedRelationships": [
            "FAILURE."
          ]
        },
        {
          "connectionIdentifier": "c425ea01-34a2-3311-b8f1-e381089803d0",
          "name": "",
          "selectedRelationships": [
            "unmatched"
          ]
        },
        {
          "connectionIdentifier": "1eb29693-3681-3e54-862a-461c1872e8a4",
          "name": "",
          "selectedRelationships": [
            "fail_check"
          ]
        },
        {
          "connectionIdentifier": "13e259ad-1745-3b2d-89a8-a5d1f4b35ded",
          "name": "",
          "selectedRelationships": [
            "unmatched"
          ]
        }
      ],
      "destinationConnectionIds": [
        {
          "connectionIdentifier": "71a88a00-cc29-3c47-9956-ad765ff0d447",
          "name": "",
          "selectedRelationships": [
            "check route code"
          ]
        },
        {
          "connectionIdentifier": "2efb85ae-ec56-3a0d-b245-206fa7000496",
          "name": "",
          "selectedRelationships": [
            "unmatched"
          ]
        },
        {
          "connectionIdentifier": "eaccf0b6-aa59-398e-b130-d1df5099de79",
          "name": "",
          "selectedRelationships": []
        }
      ],
      "allDestinationIds": [
        "0d2c922d-c4a3-3b0f-bc98-d4e6aef2c98a",
        "382d3d98-85f7-3eaf-a124-c6845687a5fa"
      ],
      "sortedDestinations": [],
      "leaf": false,
      "start": false,
      "end": false
    }

  }

}
4

1 回答 1

2

nifi 使用 json 路径的这种实现:https ://github.com/json-path/JsonPath#filter-operators

它只支持对数组进行过滤

因此,在过滤地图之前,您必须使用“转换”它的所有值到一个数组[*]

这应该工作:

$.processorMap[*][?(@.name=='set value for mongo')]

我还发现了以下在线资源来验证基于相同实现的 json 路径:

https://jsonpath.herokuapp.com/

于 2020-03-31T04:49:23.650 回答