我对Elasticsearch有点陌生,我有一个正则表达式,我正在尝试使用Java插入 flex 搜索,并且遇到了我尝试使用/作为转义字符的解析错误,但仍然失败。有人可以告诉我我想念的吗?

String workflow = "{\"WORKFLOW_ID\":1,\"NAME\":\"Test  Workflow\",\"DESCRIPTION\":\"This workflow will be used for testing\",\"COMPANY_ID\":237,\"SOURCE_ID\":1,\"NODES\":[{\"NODE_ID\":\"node-220ae87b-f74d-22a5-8661-a1d189983bf4\",\"POSITION_X\":0,\"POSITION_Y\":120,\"WORKFLOW_ID\":1,\"NAME\":\"Start Node\",\"TYPE\":\"START_NODE\",\"COMPANY_ID\":237,\"CONNECTIONS_TO\":[{\"FROM\":\"a\",\"TO_NODE\":\"node-220ae87b-f74d-22a5-8661-a1d189983bf5\"}],\"VALUES\":{}},{\"NODE_ID\":\"node-220ae87b-f74d-22a5-8661-a1d189983bf5\",\"POSITION_X\":120,\"POSITION_Y\":240,\"WORKFLOW_ID\":1,\"NAME\":\"Route Node1\",\"TYPE\":\"ROUTE_NODE\",\"COMPANY_ID\":237,\"CONNECTIONS_TO\":[{\"FROM\":\"a\",\"TO_NODE\":\"node-220ae87b-f74d-22a5-8661-a1d189983bf6\"},{\"FROM\":\"b\",\"TO_NODE\":\"node-220ae87b-f74d-22a5-8661-a1d189983bf7\"}],\"VALUES\":{\"VARIABLE\":{\"NAME\":\"Subject\",\"TYPE\":\"String\"},\"CONDITIONS\":[{\"ORDER\":0,\"OPERATOR\":\"Regex\",\"VALUE\":\"\\[#([0-9]+)\\]\",\"TO_NODE\":\"node-220ae87b-f74d-22a5-8661-a1d189983bf6\"},{\"ORDER\":1,\"OPERATOR\":\"\",\"VALUE\":null,\"TO_NODE\":\"node-220ae87b-f74d-22a5-8661-a1d189983bf7\"}]}},{\"NODE_ID\":\"node-220ae87b-f74d-22a5-8661-a1d189983bf6\",\"POSITION_X\":120,\"POSITION_Y\":240,\"WORKFLOW_ID\":1,\"NAME\":\"Work action1\",\"TYPE\":\"WORK_ACTION_NODE\",\"COMPANY_ID\":237,\"CONNECTIONS_TO\":[],\"VALUES\":{\"WORK_ACTION_TYPE\":\"Ticket\",\"STATUS\":\"New\"}},{\"NODE_ID\":\"node-220ae87b-f74d-22a5-8661-a1d189983bf7\",\"POSITION_X\":120,\"POSITION_Y\":240,\"WORKFLOW_ID\":1,\"NAME\":\"Work action2\",\"TYPE\":\"WORK_ACTION_NODE\",\"COMPANY_ID\":237,\"CONNECTIONS_TO\":[],\"VALUES\":{\"WORK_ACTION_TYPE\":\"Ticket\",\"STATUS\":\"Open\"}}]}";

这是我用来将数据放入elasticsearch的代码
IndexResponse rescreate = Consumer.client.prepareIndex("workflows", "workflow").setSource(workflow.toString(), XContentType.JSON).get();

那是我的jsonobject,这是我得到的错误,我正试图传递的正则表达式为\ [#([0-9] +)\]。

最佳答案

对于任何可能遇到此问题的人。我将String格式的json对象再次转换为String,因此遇到了此问题。

字符串工作流程=“{\” WORKFLOW_ID \“:1,\” NAME \“:\” Test Workflow \“,\” DESCRIPTION \“:\”此工作流程将用于测试\“,\” COMPANY_ID \“: 237,\“SOURCE_ID \”:1,\“NODES \”:[{\“NODE_ID \”:\“node-220ae87b-f74d-22a5-8661-a1d189983bf4 \”,\“POSITION_X \”:0,\“POSITION_Y \“:120,\” WORKFLOW_ID \“:1,\” NAME \“:\”开始节点\“,\” TYPE \“:\” START_NODE \“,\” COMPANY_ID \“:237,\” CONNECTIONS_TO \“:[{\” FROM \“:\” a \“,\” TO_NODE \“:\” node-220ae87b-f74d-22a5-8661-a1d189983bf5 \“}],\” VALUES \“:{}} ,{\“NODE_ID \”:\“node-220ae87b-f74d-22a5-8661-a1d189983bf5 \”,\“POSITION_X \”:120,\“POSITION_Y \”:240,\“WORKFLOW_ID \”:1,\“NAME \“:\” Route Node1 \“,\” TYPE \“:\” ROUTE_NODE \“,\” COMPANY_ID \“:237,\” CONNECTIONS_TO \“:[{\” FROM \“:\” a \“,\“TO_NODE \”:\“node-220ae87b-f74d-22a5-8661-a1d189983bf6 \”},{\“FROM \”:\“b \”,\“TO_NODE \”:\“node-220ae87b-f74d -22a5-8661-a1d189983bf7 \“}],\” VALUES \“:{\” VARIABLE \“:{\” NAME \“:\” Subject \“,\” TYPE \“:\” String \“}, \“CONDITIONS \”:[{\“ORDER \”:0,\“OPERATOR \”:\“Regex \”,\“VALUE \”:\“\ [#([0-9] +)\] \ “,\” TO_NODE \“:\” node-220ae87b-f74d-22a 5-8661-a1d189983bf6 \“},{\” ORDER \“:1,\” OPERATOR \“:\” \“,\” VALUE \“:null,\” TO_NODE \“:\” node-220ae87b-f74d -22a5-8661-a1d189983bf7 \“}]}},{\” NODE_ID \“:\” node-220ae87b-f74d-22a5-8661-a1d189983bf6 \“,\” POSITION_X \“:120,\” POSITION_Y \“: 240,\“WORKFLOW_ID \”:1,\“NAME \”:\“工作 Action 1 \”,\“TYPE \”:\“WORK_ACTION_NODE \”,\“COMPANY_ID \”:237,\“CONNECTIONS_TO \”:[ ],\“VALUES \”:{\“WORK_ACTION_TYPE \”:\“Ticket \”,\“STATUS \”:\“New \”}}},{\“NODE_ID \”:\“node-220ae87b-f74d- 22a5-8661-a1d189983bf7 \“,\” POSITION_X \“:120,\” POSITION_Y \“:240,\” WORKFLOW_ID \“:1,\” NAME \“:\” Work action2 \“,\” TYPE \“:\“WORK_ACTION_NODE \”,\“COMPANY_ID \”:237,\“CONNECTIONS_TO \”:[],\“VALUES \”:{\“WORK_ACTION_TYPE \”:\“Ticket \”,\“STATUS \”:\ “打开\”}}]}”;

IndexResponse rescreate = Consumer.client.prepareIndex(“workflows”,“workflow”)。setSource(workflow,XContentType.JSON).get();

仅执行工作流程即可。 working.toString()导致问题

07-24 14:40