How to create or verify ElementRangeIndexes in Marklogic from Flyway script. It is a pain to remember the elementRangeIndex to be manually don eon every Marklogic DB we migrate.
Asked
Active
Viewed 57 times
1 Answers
1
You may be able to use the Flyway gradle plugin, to execute ml-gradle configuration scripts.
Alternatively, you can use gradle to execute curl commands and create the indexes using the MarkLogic Management API endpoints.
An example of using Curl to define an index taken from Learning the MarkLogic REST API:
curl -X PUT --anyauth --user admin:admin --header "Content-Type:application/json" \
-d '{"word-positions": true,
"element-word-positions": true,
"range-element-index":
[ { "scalar-type": "string",
"namespace-uri": "",
"localname": "SPEAKER",
"collation": "http://marklogic.com/collation/",
"range-value-positions": false,
"invalid-values": "reject"
},
{ "scalar-type": "string",
"namespace-uri": "",
"localname": "affiliation",
"collation": "http://marklogic.com/collation/",
"range-value-positions": false,
"invalid-values": "reject"
},
{ "scalar-type": "int",
"namespace-uri": "",
"localname": "contentRating",
"collation": "",
"range-value-positions": false,
"invalid-values": "reject"
},
{ "scalar-type": "unsignedLong",
"namespace-uri": "http://marklogic.com/filter",
"localname": "size",
"collation": "",
"range-value-positions": false,
"invalid-values": "reject"
},
{ "scalar-type": "string",
"namespace-uri": "http://marklogic.com/filter",
"localname": "Exposure_Time",
"collation": "http://marklogic.com/collation/",
"range-value-positions": false,
"invalid-values": "reject"
}]}' \
http://localhost:8002/manage/v2/databases/TutorialDB/properties

Mike Gardner
- 6,611
- 5
- 24
- 34
-
Thanks Michael I will surely try this – stillanovice Jun 02 '20 at 15:34
-
Also is there a way to check if the index exists before creating it? – stillanovice Jun 02 '20 at 16:07
-
@stillanovice Same endpoint, [with a GET](https://docs.marklogic.com/REST/GET/manage/v2/databases/[id-or-name]/properties) instead of PUT – Mike Gardner Jun 02 '20 at 18:27
-
I could get the range index data with the admin user. However with an user with rest_writer role I am not able to. Getting the error as below. Wanted to know if there is any specific role taht i can create a user to test as I cannot use the admin user in PRod. – stillanovice Jun 03 '20 at 20:08