Skip to content

Instantly share code, notes, and snippets.

@dmcassel
Forked from evanlenz/ex01.sh
Last active September 23, 2015 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmcassel/4705952c729558f90b0b to your computer and use it in GitHub Desktop.
Save dmcassel/4705952c729558f90b0b to your computer and use it in GitHub Desktop.
Code samples for MarkLogic REST API
curl -X GET \
--anyauth --user rest-writer:x \
'http://localhost:8011/v1/search?q=chicken&format=json'
curl -v -X PUT \
--digest --user rest-writer:x \
-d'{"recipe":"Apple pie", "fromScratch":true, "ingredients":"The Universe"}' \
-H "Content-type: application/json" \
'http://localhost:8011/v1/documents?uri=/example/recipe.json'
curl -v -X PUT \
--digest --user rest-writer:x \
-d'{"recipe":"Apple pie", "fromScratch":true, "ingredients":"The Universe"}' \
'http://localhost:8011/v1/documents?uri=/example/recipe.json&format=json'
curl -v -X PUT \
--digest --user rest-writer:x \
-d'<person><first>Carl</first><last>Sagan</last></person>' \
'http://localhost:8011/v1/documents?uri=/example/person.xml'
curl -v -X PUT \
--digest --user rest-writer:x \
-d'<person><first>Carl</first><last>Sagan</last></person>' \
-H "Content-type: application/xml" \
'http://localhost:8011/v1/documents?uri=/example/person.xml'
curl -v -X PUT \
--digest --user rest-writer:x \
-d'This is a text file.' \
-H "Content-type: text/plain" \
'http://localhost:8011/v1/documents?uri=/foo.txt&collection=examples&collection=mine'
curl http://developer.marklogic.com/media/learn/rest/mlfavicon.png >mlfavicon.png
curl -v -X PUT \
--digest --user rest-writer:x \
--data-binary '@mlfavicon.png' \
-H "Content-type: image/png" \
'http://localhost:8011/v1/documents?uri=/example/mlfavicon.png&extract=properties'
curl -v -X DELETE \
--digest --user rest-writer:x \
'http://localhost:8011/v1/documents?uri=/foo.txt'
curl -v -X POST \
--digest --user rest-writer:x \
-d'{"query":{"properties-query":{"term-query":{"text":"fish"}}}}' \
-H "Content-type: application/json" \
'http://localhost:8011/v1/search?format=json'
curl -v -X POST \
--digest --user rest-writer:x \
-d'<query xmlns="http://marklogic.com/appservices/search"><properties-query><term-query><text>fish</text></term-query></properties-query></query>' \
-H "Content-type: application/xml" \
'http://localhost:8011/v1/search'
"total":95,"start":1,"page-length":10
"results": [
{
"index": 1,
"uri": "/guide/search-dev.xml",
"path": "fn:doc(\"/guide/search-dev.xml\")",
"score": 92032,
"confidence": 0.672178,
"fitness": 0.877356,
"matches": [
{
"path": "fn:doc(\"/guide/search-dev.xml\")/*:guide/*:para[5]",
"match-text": [
"Lexicon and ",
{
"highlight": "Range Index"
},
"-Based APIs..."
},
{
"path": "fn:doc(\"/guide/search-dev.xml\")/*:guide/*:para[20]",
"match-text": [
"no matter what the database size. As part of loading a document, full-text ",
{
"highlight": "indexes"
},
"are created making arbitrary searches fast. Searches automatically use the"
}
]
}
]
"results": [
{
"index": 1,
"uri": "/guide/search-dev.xml",
"path": "fn:doc(\"/guide/search-dev.xml\")",
"score": 92032,
"confidence": 0.672178,
"fitness": 0.877356,
"matches": [
{
"path": "fn:doc(\"/guide/search-dev.xml\")/*:guide/*:para[5]",
"match-text": [
"Lexicon and ",
{
"highlight": "Range Index"
},
"-Based APIs..."
},
{
"path": "fn:doc(\"/guide/search-dev.xml\")/*:guide/*:para[20]",
"match-text": [
"no matter what the database size. As part of loading a document, full-text ",
{
"highlight": "indexes"
},
"are created making arbitrary searches fast. Searches automatically use the"
}
]
}
]
"total":95,"start":1,"page-length":10
"results": [
{
"index": 1,
"uri": "/guide/search-dev.xml",
"path": "fn:doc(\"/guide/search-dev.xml\")",
"score": 92032,
"confidence": 0.672178,
"fitness": 0.877356,
"matches": [
{
"path": "fn:doc(\"/guide/search-dev.xml\")/*:guide/*:para[5]",
"match-text": [
"Lexicon and ",
{
"highlight": "Range Index"
},
"-Based APIs..."
},
{
"path": "fn:doc(\"/guide/search-dev.xml\")/*:guide/*:para[20]",
"match-text": [
"no matter what the database size. As part of loading a document, full-text ",
{
"highlight": "indexes"
},
"are created making arbitrary searches fast. Searches automatically use the"
}
]
}
]
[{"name":"default","uri":"/v1/config/query/default"}]
<!--...-->
<result index="1"
uri="/guide/search-dev.xml"
path="fn:doc(&quot;/guide/search-dev.xml&quot;)"
score="92032"
confidence="0.672178"
fitness="0.877356">
<snippet>
<match path="fn:doc(&quot;/guide/search-dev.xml&quot;)/*:guide/*:para[5]"
>Lexicon and <highlight>Range Index</highlight>-Based APIs...</match>
<match path="fn:doc(&quot;/guide/search-dev.xml&quot;)/*:guide/*:para[20]"
>no matter what the database size. As part of loading a document,
full-text <highlight>indexes</highlight> are created making
arbitrary searches fast. Searches automatically use the</match>
</snippet>
</result>
<!--...-->
curl -v -X PUT \
--digest --user rest-admin:x \
-d'{options:{constraint:[{name:"tag",collection:{prefix:""}}]}}' \
-H "Content-type: application/json" \
'http://localhost:8011/v1/config/query/tutorial'
<!--...-->
<result index="1"
uri="/guide/search-dev.xml"
path="fn:doc(&quot;/guide/search-dev.xml&quot;)"
score="92032"
confidence="0.672178"
fitness="0.877356">
<snippet>
<match path="fn:doc(&quot;/guide/search-dev.xml&quot;)/*:guide/*:para[5]"
>Lexicon and <highlight>Range Index</highlight>-Based APIs...</match>
<match path="fn:doc(&quot;/guide/search-dev.xml&quot;)/*:guide/*:para[20]"
>no matter what the database size. As part of loading a document,
full-text <highlight>indexes</highlight> are created making
arbitrary searches fast. Searches automatically use the</match>
</snippet>
</result>
<!--...-->
[{"name":"default","uri":"/v1/config/query/default"}]
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="tag">
<collection prefix=""/>
</constraint>
</options>
<rapi:query-options xmlns:rapi="http://marklogic.com/rest-api">
<rapi:options>
<rapi:name>default</rapi:name>
<rapi:uri>/v1/config/query/default</rapi:uri>
</rapi:options>
</rapi:query-options>
[{"name":"default","uri":"/v1/config/query/default"}]
curl -v -X PUT \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"tag","collection":{"prefix":""}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"constraint": [
{
"collection": {
"prefix": ""
},
"name": "tag"
}
]
}
}
curl -v -X PUT \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"tag","collection":{"prefix":""}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"constraint": [
{
"collection": {
"prefix": ""
},
"name": "tag"
}
]
}
}
// create a search definition using the "tutorial" options
StringQueryDefinition query = queryMgr.newStringDefinition("tutorial");
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="tag">
<collection prefix=""/>
</constraint>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"company","value":{"json-key":"affiliation"}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="tag">
<collection prefix=""/>
</constraint>
</options>
{
"options": {
"constraint": [
{
"name": "company",
"value": {
"json-key": "affiliation"
}
}
]
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"company","value":{"json-property":"affiliation"}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"constraint": [
{
"name": "company",
"value": {
"json-property": "affiliation"
}
}
]
}
}
// find plays featuring the King of France
query.setCriteria("person:\"KING OF FRANCE\"");
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="company">
<value>
<json-key>affiliation</json-key>
</value>
</constraint>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"person","value":{"element":{"name":"SPEAKER","ns":""}}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="company">
<value>
<json-property>affiliation</json-property>
</value>
</constraint>
</options>
{
"options": {
"constraint": [
{
"name": "person",
"value": {
"element": {
"name": "SPEAKER",
"ns": ""
}
}
}
]
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"person","value":{"element":{"name":"PERSONA","ns":""}}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"constraint": [
{
"name": "person",
"value": {
"element": {
"name": "PERSONA",
"ns": ""
}
}
}
]
}
}
tutorialOpts.addConstraint(
qob.constraint("stagedir",
qob.word(
qob.elementTermIndex(new QName("STAGEDIR")))));
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="person">
<value>
<element ns="" name="PERSONA"/>
</value>
</constraint>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"bio","word":{"json-key":"bio"}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="person">
<value>
<element ns="" name="PERSONA"/>
</value>
</constraint>
</options>
{
"options": {
"constraint": [
{
"name": "bio",
"word": {
"json-key": "bio"
}
}
]
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"bio","word":{"json-property":"bio"}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"constraint": [
{
"name": "bio",
"word": {
"json-property": "bio"
}
}
]
}
}
// search for mentions of swords in the script itself
query.setCriteria("spoken:sword");
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="bio">
<word>
<json-key>bio</json-key>
</word>
</constraint>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"stagedir","word":{"element":{"name":"STAGEDIR","ns":""}}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="bio">
<word>
<json-property>bio</json-property>
</word>
</constraint>
</options>
{
"options": {
"constraint": [
{
"name": "stagedir",
"word": {
"element": {
"name": "STAGEDIR",
"ns": ""
}
}
}
]
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"stagedir","word":{"element":{"name":"STAGEDIR","ns":""}}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"constraint": [
{
"name": "stagedir",
"word": {
"element": {
"name": "STAGEDIR",
"ns": ""
}
}
}
]
}
}
// create a query builder using the "tutorial" options
StructuredQueryBuilder qb = new StructuredQueryBuilder("tutorial");
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="stagedir">
<word>
<element ns="" name="STAGEDIR"/>
</word>
</constraint>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"spoken","element-query":{"name":"SPEECH","ns":""}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="stagedir">
<word>
<element ns="" name="STAGEDIR"/>
</word>
</constraint>
</options>
{
"options": {
"constraint": [
{
"element-query": {
"name": "SPEECH",
"ns": ""
},
"name": "spoken"
}
]
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"spoken","element-query":{"name":"SPEECH","ns":""}}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"constraint": [
{
"element-query": {
"name": "SPEECH",
"ns": ""
},
"name": "spoken"
}
]
}
}
// create a builder for constructing query options
QueryOptionsBuilder qob = new QueryOptionsBuilder();
// expose the collection lexicon as "tag" values
QueryOptionsHandle options = new QueryOptionsHandle().withValues(
qob.values("tag",
qob.collection("")));
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="spoken">
<element-query ns="" name="SPEECH"/>
</constraint>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"image","properties":null}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="spoken">
<element-query ns="" name="SPEECH"/>
</constraint>
</options>
{
"options": {
"constraint": [
{
"name": "image",
"properties": null
}
]
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"image","properties":null}]}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"constraint": [
{
"name": "image",
"properties": null
}
]
}
}
// retrieve the values
ValuesHandle valuesHandle = queryMgr.values(valuesDef, new ValuesHandle());
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="image">
<properties/>
</constraint>
</options>
{"query":
{"or-query":
{"queries":[
{"and-query":
{"queries":[
{"word-constraint-query":
{"constraint-name":"bio",
"text":["product"]}},
{"value-constraint-query":
{"constraint-name":"company",
"text":["MarkLogic"]}}]}},
{"and-query":
{"queries":[
{"element-constraint-query":
{"constraint-name":"spoken",
"and-query":
{"queries":[
{"term-query":
{"text":["fie"]}}]}}},
{"word-constraint-query":
{"constraint-name":"stagedir",
"text":["fall"]}},
{"value-constraint-query":
{"constraint-name":"person",
"text":["GRUMIO"]}}]}},
{"and-query":
{"queries":[
{"properties-query":
{"term-query":
{"text":["fish"]}}},
{"infinite":true,
"directory-query":
{"uri":["/images/2012/02/27/"]}}]}},
{"and-query":
{"queries":[
{"collection-query":
{"uri":["mlw2012"]}},
{"term-query":
{"text":["fun"]}}]}}]}}}
// print out the values and their frequencies
for (CountedDistinctValue value : valuesHandle.getValues()) {
System.out.println(
value.get("xs:string",String.class) + ": " + value.getCount());
}
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="image">
<properties/>
</constraint>
</options>
{"query":
{"or-query":
{"queries":[
{"and-query":
{"queries":[
{"word-constraint-query":
{"constraint-name":"bio",
"text":["product"]}},
{"value-constraint-query":
{"constraint-name":"company",
"text":["MarkLogic"]}}]}},
{"and-query":
{"queries":[
{"element-constraint-query":
{"constraint-name":"spoken",
"and-query":
{"queries":[
{"term-query":
{"text":["fie"]}}]}}},
{"word-constraint-query":
{"constraint-name":"stagedir",
"text":["fall"]}},
{"value-constraint-query":
{"constraint-name":"person",
"text":["GRUMIO"]}}]}},
{"and-query":
{"queries":[
{"properties-query":
{"term-query":
{"text":["fish"]}}},
{"infinite":true,
"directory-query":
{"uri":["/images/2012/02/27/"]}}]}},
{"and-query":
{"queries":[
{"collection-query":
{"uri":["mlw2012"]}},
{"term-query":
{"text":["fun"]}}]}}]}}}
// expose the URI lexicon as "uri" values
QueryOptionsHandle options = new QueryOptionsHandle().withValues(
qob.values("uri",
qob.uri()));
<query xmlns="http://marklogic.com/appservices/search">
<or-query>
<and-query>
<word-constraint-query>
<constraint-name>bio</constraint-name>
<text>product</text>
</word-constraint-query>
<value-constraint-query>
<constraint-name>company</constraint-name>
<text>MarkLogic</text>
</value-constraint-query>
</and-query>
<and-query>
<element-constraint-query>
<constraint-name>spoken</constraint-name>
<term-query>
<text>fie</text>
</term-query>
</element-constraint-query>
<word-constraint-query>
<constraint-name>stagedir</constraint-name>
<text>fall</text>
</word-constraint-query>
<value-constraint-query>
<constraint-name>person</constraint-name>
<text>GRUMIO</text>
</value-constraint-query>
</and-query>
<and-query>
<properties-query>
<term-query>
<text>fish</text>
</term-query>
</properties-query>
<directory-query>
<uri>/images/2012/02/27/</uri>
<infinite>true</infinite>
</directory-query>
</and-query>
<and-query>
<collection-query>
<uri>mlw2012</uri>
</collection-query>
<term-query>
<text>fun</text>
</term-query>
</and-query>
</or-query>
</query>
curl -v -X POST \
--digest --user rest-writer:x \
-H "Content-type: application/json" \ -d'{"query":{"or-query":{"queries":[{"and-query":{"queries":[ {"word-constraint-query":{"constraint-name":"bio","text":["product"]}}, {"value-constraint-query":{"constraint-name":"company","text":["MarkLogic"]}} ]}}, {"and-query":{"queries":[ {"element-constraint-query":{"constraint-name":"spoken","and-query": {"queries":[{"term-query":{"text":["fie"]}}]} }}, {"word-constraint-query":{"constraint-name":"stagedir","text":["fall"]}}, {"value-constraint-query":{"constraint-name":"person","text":["GRUMIO"]}} ]}}, {"and-query":{"queries":[ {"properties-query":{"term-query":{"text":["fish"]}}}, {"directory-query":{"uri":["/images/2012/02/27/"]},"infinite":true} ]}}, {"and-query":{"queries":[ {"collection-query":{"uri":["mlw2012"]}}, {"term-query":{"text":["fun"]}} ]}}]}}}' \
'http://localhost:8011/v1/search?options=tutorial'
<query xmlns="http://marklogic.com/appservices/search">
<or-query>
<and-query>
<word-constraint-query>
<constraint-name>bio</constraint-name>
<text>product</text>
</word-constraint-query>
<value-constraint-query>
<constraint-name>company</constraint-name>
<text>MarkLogic</text>
</value-constraint-query>
</and-query>
<and-query>
<element-constraint-query>
<constraint-name>spoken</constraint-name>
<term-query>
<text>fie</text>
</term-query>
</element-constraint-query>
<word-constraint-query>
<constraint-name>stagedir</constraint-name>
<text>fall</text>
</word-constraint-query>
<value-constraint-query>
<constraint-name>person</constraint-name>
<text>GRUMIO</text>
</value-constraint-query>
</and-query>
<and-query>
<properties-query>
<term-query>
<text>fish</text>
</term-query>
</properties-query>
<directory-query>
<uri>/images/2012/02/27/</uri>
<infinite>true</infinite>
</directory-query>
</and-query>
<and-query>
<collection-query>
<uri>mlw2012</uri>
</collection-query>
<term-query>
<text>fun</text>
</term-query>
</and-query>
</or-query>
</query>
curl -v -X POST \
--digest --user rest-writer:x \
-H "Content-type: application/json" \ -d'{"query":{"or-query":{"queries":[{"and-query":{"queries":[ {"word-constraint-query":{"constraint-name":"bio","text":["product"]}}, {"value-constraint-query":{"constraint-name":"company","text":["MarkLogic"]}} ]}}, {"and-query":{"queries":[ {"element-constraint-query":{"constraint-name":"spoken","and-query": {"queries":[{"term-query":{"text":["fie"]}}]} }}, {"word-constraint-query":{"constraint-name":"stagedir","text":["fall"]}}, {"value-constraint-query":{"constraint-name":"person","text":["GRUMIO"]}} ]}}, {"and-query":{"queries":[ {"properties-query":{"term-query":{"text":["fish"]}}}, {"directory-query":{"uri":["/images/2012/02/27/"]},"infinite":true} ]}}, {"and-query":{"queries":[ {"collection-query":{"uri":["mlw2012"]}}, {"term-query":{"text":["fun"]}} ]}}]}}}' \
'http://localhost:8011/v1/search?options=tutorial'
{
"options": {
"values": {
"collection": {
"prefix": ""
},
"name": "tag"
}
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"values":{"name":"tag","collection":{"prefix":""}}}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"values": {
"collection": {
"prefix": ""
},
"name": "tag"
}
}
}
// expose the "contentRating" JSON key range index as "rating" values
QueryOptionsHandle options = new QueryOptionsHandle().withValues(
qob.values("rating",
qob.range(
qob.jsonRangeIndex("contentRating",
qob.rangeType("xs:int")))));
<options xmlns="http://marklogic.com/appservices/search">
<values name="tag">
<collection prefix=""/>
</values>
</options>
// create a values definition
ValuesDefinition valuesDef = queryMgr.newValuesDefinition("rating", optionsName);
<options xmlns="http://marklogic.com/appservices/search">
<values name="tag">
<collection prefix=""/>
</values>
</options>
{
"values-response": {
"metrics": {
"aggregate-resolution-time": "PT0.000017S",
"total-time": "PT0.001675S",
"values-resolution-time": "PT0.000189S"
},
"distinct-value": [
{
"_value": "mlw2012",
"frequency": 88
},
{
"_value": "photos",
"frequency": 140
},
{
"_value": "shakespeare",
"frequency": 22
}
],
"type": "xs:string",
"name": "tag"
}
}
// also retrieve the averages of all ratings
valuesDef.setAggregate("avg","median");
<values-response name="tag" type="xs:string" xmlns="http://marklogic.com/appservices/search">
<distinct-value frequency="88">mlw2012</distinct-value>
<distinct-value frequency="140">photos</distinct-value>
<distinct-value frequency="22">shakespeare</distinct-value>
<metrics>
<values-resolution-time>PT0.000195S</values-resolution-time>
<aggregate-resolution-time>PT0.000017S</aggregate-resolution-time>
<total-time>PT0.001873S</total-time>
</metrics>
</values-response>
{
"values-response": {
"metrics": {
"aggregate-resolution-time": "PT0.000017S",
"total-time": "PT0.001675S",
"values-resolution-time": "PT0.000189S"
},
"distinct-value": [
{
"_value": "mlw2012",
"frequency": 88
},
{
"_value": "photos",
"frequency": 140
},
{
"_value": "shakespeare",
"frequency": 22
}
],
"type": "xs:string",
"name": "tag"
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"values":{"name":"uri","uri":null}}}' \
'http://localhost:8011/v1/config/query/tutorial'
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/xml" \
-d'<options xmlns="http://marklogic.com/appservices/search"><values name="uri"><uri/></values></options>' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"values": {
"name": "uri",
"uri": null
}
}
}
<options xmlns="http://marklogic.com/appservices/search">
<values name="uri">
<uri/>
</values>
</options>
{
"options": {
"values": {
"name": "uri",
"uri": null
}
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"values":{"name":"company","range":{"type":"xs:string","collation":"http://marklogic.com/collation/","json-key":"affiliation"},"values-option":["frequency-order"]}}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<values name="uri">
<uri/>
</values>
</options>
{
"options": {
"values": {
"name": "company",
"range": {
"collation": "http://marklogic.com/collation/",
"json-key": "affiliation",
"type": "xs:string"
},
"values-option": [
"frequency-order"
]
}
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"values":{"name":"company","range":{"type":"xs:string","collation":"http://marklogic.com/collation/","json-key":"affiliation"},"values-option":["frequency-order"]}}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"values": {
"name": "company",
"range": {
"collation": "http://marklogic.com/collation/",
"json-key": "affiliation",
"type": "xs:string"
},
"values-option": [
"frequency-order"
]
}
}
}
// print out each size/exposure co-occurrence
for (Tuple tuple : tuplesHandle.getTuples()) {
<options xmlns="http://marklogic.com/appservices/search">
<values name="company">
<range type="xs:string" collation="http://marklogic.com/collation/">
<json-key>affiliation</json-key>
</range>
<values-option>frequency-order</values-option>
</values>
</options>
{
"options": {
"values": {
"range": {
"collation": "http://marklogic.com/collation/",
"type": "xs:string",
"element": {
"ns": "",
"name": "SPEAKER"
}
},
"name": "speaker",
"values-option": [
"frequency-order"
]
}
}
}
<options xmlns="http://marklogic.com/appservices/search">
<values name="company">
<range type="xs:string" collation="http://marklogic.com/collation/">
<json-key>affiliation</json-key>
</range>
<values-option>frequency-order</values-option>
</values>
</options>
{
"options": {
"values": {
"range": {
"collation": "http://marklogic.com/collation/",
"type": "xs:string",
"element": {
"ns": "",
"name": "SPEAKER"
}
},
"name": "speaker",
"values-option": [
"frequency-order"
]
}
}
}
QueryOptionsHandle options = new QueryOptionsHandle().withConstraints(
// expose the "contentRating" JSON key range index as "rating" values
qob.constraint("rating",
qob.range(
qob.jsonRangeIndex("contentRating",
qob.rangeType("xs:int")),
Facets.FACETED,
FragmentScope.DOCUMENTS,
qob.buckets(),
"descending")), // highest ratings first
// expose the "affiliation" JSON key range index as "company" values
qob.constraint("company",
qob.range(
qob.jsonRangeIndex("affiliation",
qob.stringRangeType(QueryOptions.DEFAULT_COLLATION)),
Facets.FACETED,
FragmentScope.DOCUMENTS,
qob.buckets(),
"frequency-order"))); // most common values first
<options xmlns="http://marklogic.com/appservices/search">
<values name="speaker">
<values-option>frequency-order</values-option>
<range type="xs:string" collation="http://marklogic.com/collation/">
<element ns="" name="SPEAKER"/>
</range>
</values>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"values":{"name":"speaker","range":{"type":"xs:string","collation":"http://marklogic.com/collation/","element":{"name":"SPEAKER","ns":""}},"values-option":["frequency-order"]}}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<values name="speaker">
<values-option>frequency-order</values-option>
<range type="xs:string" collation="http://marklogic.com/collation/">
<element ns="" name="SPEAKER"/>
</range>
</values>
</options>
{
"options": {
"values": {
"range": {
"json-key": "contentRating",
"type": "xs:int"
},
"name": "rating"
}
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"values":{"name":"speaker","range":{"type":"xs:string","collation":"http://marklogic.com/collation/","element":{"name":"SPEAKER","ns":""}},"values-option":["frequency-order"]}}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"values": {
"range": {
"json-key": "contentRating",
"type": "xs:int"
},
"name": "rating"
}
}
}
<options xmlns="http://marklogic.com/appservices/search">
<values name="rating">
<range type="xs:int">
<json-key>contentRating</json-key>
</range>
</values>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"values":{"name":"rating","range":{"type":"xs:int","json-key":"contentRating"}}}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<values name="rating">
<range type="xs:int">
<json-key>contentRating</json-key>
</range>
</values>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"values":{"name":"rating","range":{"type":"xs:int","json-key":"contentRating"}}}}' \
'http://localhost:8011/v1/config/query/tutorial'
<!--...-->
<aggregate-result name="avg">3.71839080459770115</aggregate-result>
<aggregate-result name="median">4</aggregate-result>
<!--...-->
"aggregate-result": [
{
"_value": "3.71839080459770115",
"name": "avg"
},
{
"_value": "4",
"name": "median"
}
]
<!--...-->
<aggregate-result name="avg">3.71839080459770115</aggregate-result>
<aggregate-result name="median">4</aggregate-result>
<!--...-->
"aggregate-result": [
{
"_value": "3.71839080459770115",
"name": "avg"
},
{
"_value": "4",
"name": "median"
}
]
{
"options": {
"values": {
"range": {
"json-key": "contentRating",
"type": "xs:int"
},
"name": "rating"
}
}
}
<options xmlns="http://marklogic.com/appservices/search">
<values name="rating">
<range type="xs:int">
<json-key>contentRating</json-key>
</range>
</values>
</options>
curl -v -X POST \ --digest --user rest-admin:x \ -H "Content-type: application/json" \
-d'{"options":{"values":{"name":"rating","range":{"type":"xs:int","json-key":"contentRating"}}}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<values name="rating">
<range type="xs:int">
<json-key>contentRating</json-key>
</range>
</values>
</options>
{
"options": {
"tuples": {
"range": [
{
"type": "xs:unsignedLong",
"element": {
"ns": "http://marklogic.com/filter",
"name": "size"
}
},
{
"collation": "http://marklogic.com/collation/",
"type": "xs:string",
"element": {
"ns": "http://marklogic.com/filter",
"name": "Exposure_Time"
}
}
],
"name": "size-exposure"
}
}
}
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"values":{"name":"rating","range":{"type":"xs:int","json-key":"contentRating"}}}}' \
'http://localhost:8011/v1/config/query/tutorial'
{
"options": {
"tuples": {
"range": [
{
"type": "xs:unsignedLong",
"element": {
"ns": "http://marklogic.com/filter",
"name": "size"
}
},
{
"collation": "http://marklogic.com/collation/",
"type": "xs:string",
"element": {
"ns": "http://marklogic.com/filter",
"name": "Exposure_Time"
}
}
],
"name": "size-exposure"
}
}
}
<options xmlns="http://marklogic.com/appservices/search">
<tuples name="size-exposure">
<range type="xs:unsignedLong">
<element ns="http://marklogic.com/filter" name="size"/>
</range>
<range type="xs:string" collation="http://marklogic.com/collation/">
<element ns="http://marklogic.com/filter" name="Exposure_Time"/>
</range>
</tuples>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \ -d'{"options":{"tuples":{"name":"size-exposure","range":[{"type":"xs:unsignedLong","element":{"name":"size","ns":"http://marklogic.com/filter"}}, {"type":"xs:string","collation":"http://marklogic.com/collation/", "element":{"name":"Exposure_Time","ns":"http://marklogic.com/filter"} } ]}}}' \
'http://localhost:8011/v1/config/query/tutorial'
<options xmlns="http://marklogic.com/appservices/search">
<tuples name="size-exposure">
<range type="xs:unsignedLong">
<element ns="http://marklogic.com/filter" name="size"/>
</range>
<range type="xs:string" collation="http://marklogic.com/collation/">
<element ns="http://marklogic.com/filter" name="Exposure_Time"/>
</range>
</tuples>
</options>
curl -v -X POST \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"tuples":{"name":"size-exposure","range":[{"type":"xs:unsignedLong","element":{"name":"size","ns":"http://marklogic.com/filter"}}, {"type":"xs:string","collation":"http://marklogic.com/collation/", "element":{"name":"Exposure_Time","ns":"http://marklogic.com/filter"} } ]}}}' \
'http://localhost:8011/v1/config/query/tutorial'
<!--...-->
<tuple frequency="1">
<distinct-value xsi:type="xs:unsignedLong" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">60641</distinct-value>
<distinct-value xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">1/100</distinct-value>
</tuple>
<!--...-->
"tuple": [
{
"distinct-value": [
{
"_value": "60641",
"type": "xs:unsignedLong"
},
{
"_value": "1/100",
"type": "xs:string"
}
],
"frequency": 1
}
<!--...-->
<tuple frequency="1">
<distinct-value xsi:type="xs:unsignedLong" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">60641</distinct-value>
<distinct-value xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">1/100</distinct-value>
</tuple>
<!--...-->
"tuple": [
{
"distinct-value": [
{
"_value": "60641",
"type": "xs:unsignedLong"
},
{
"_value": "1/100",
"type": "xs:string"
}
],
"frequency": 1
}
<options xmlns="http://marklogic.com/appservices/search">
<!-- expose the "contentRating" JSON key range index as "rating" values -->
<constraint name="rating">
<range type="xs:int" facet="true">
<json-key>contentRating</json-key>
<!-- highest ratings first -->
<facet-option>descending</facet-option>
</range>
</constraint>
<!-- expose the "affiliation" JSON key range index as "company" values -->
<constraint name="company">
<range type="xs:string" facet="true" collation="http://marklogic.com/collation/">
<json-key>affiliation</json-key>
<!-- most common values first -->
<facet-option>frequency-order</facet-option>
</range>
</constraint>
</options>
{
"options": {
"constraint": [
{
"range": {
"json-key": "contentRating",
"type": "xs:int",
"facet-option": "descending"
},
"name": "rating"
},
{
"range": {
"collation": "http://marklogic.com/collation/",
"json-key": "affiliation",
"type": "xs:string",
"facet-option": "frequency-order"
},
"name": "company"
}
]
}
}
<options xmlns="http://marklogic.com/appservices/search">
<!-- expose the "contentRating" JSON key range index as "rating" values -->
<constraint name="rating">
<range type="xs:int" facet="true">
<json-key>contentRating</json-key>
<!-- highest ratings first -->
<facet-option>descending</facet-option>
</range>
</constraint>
<!-- expose the "affiliation" JSON key range index as "company" values -->
<constraint name="company">
<range type="xs:string" facet="true" collation="http://marklogic.com/collation/">
<json-key>affiliation</json-key>
<!-- most common values first -->
<facet-option>frequency-order</facet-option>
</range>
</constraint>
</options>
{
"options": {
"constraint": [
{
"range": {
"json-key": "contentRating",
"type": "xs:int",
"facet-option": "descending"
},
"name": "rating"
},
{
"range": {
"collation": "http://marklogic.com/collation/",
"json-key": "affiliation",
"type": "xs:string",
"facet-option": "frequency-order"
},
"name": "company"
}
]
}
}
curl -v -X PUT \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"rating","range":{"type":"xs:int","json-key":"contentRating","facet-option":"descending"}}, {"name":"company","range":{"type":"xs:string","collation":"http://marklogic.com/collation/","json-key":"affiliation","facet-option":"frequency-order"}} ]}}' \
'http://localhost:8011/v1/config/query/tutorial2'
"facets": {
"rating": {
"facetValues": [
{
"count": 61,
"name": "5"
},
{
"count": 54,
"name": "4"
},
{
"count": 34,
"name": "3"
},
{
"count": 11,
"name": "2"
},
{
"count": 2,
"name": "1"
},
{
"count": 12,
"name": "0"
}
],
"type": "xs:int"
},
"company": {
"facetValues": [
{
"count": 38,
"name": "MarkLogic"
},
{
"count": 2,
"name": "Avalon Consulting, LLC"
},
{
"count": 2,
"name": "Overstory, Ltd."
}
],
"type": "xs:string"
}
}
curl -v -X PUT \
--digest --user rest-admin:x \
-H "Content-type: application/json" \
-d'{"options":{"constraint":[{"name":"rating","range":{"type":"xs:int","json-key":"contentRating","facet-option":"descending"}}, {"name":"company","range":{"type":"xs:string","collation":"http://marklogic.com/collation/","json-key":"affiliation","facet-option":"frequency-order"}} ]}}' \
'http://localhost:8011/v1/config/query/tutorial2'
"facets": {
"rating": {
"facetValues": [
{
"count": 61,
"name": "5"
},
{
"count": 54,
"name": "4"
},
{
"count": 34,
"name": "3"
},
{
"count": 11,
"name": "2"
},
{
"count": 2,
"name": "1"
},
{
"count": 12,
"name": "0"
}
],
"type": "xs:int"
},
"company": {
"facetValues": [
{
"count": 38,
"name": "MarkLogic"
},
{
"count": 2,
"name": "Avalon Consulting, LLC"
},
{
"count": 2,
"name": "Overstory, Ltd."
}
],
"type": "xs:string"
}
}
<search:facet name="rating" type="xs:int">
<search:facet-value name="5" count="61">5</search:facet-value>
<search:facet-value name="4" count="54">4</search:facet-value>
<search:facet-value name="3" count="34">3</search:facet-value>
<search:facet-value name="2" count="11">2</search:facet-value>
<search:facet-value name="1" count="2">1</search:facet-value>
<search:facet-value name="0" count="12">0</search:facet-value>
</search:facet>
<search:facet name="company" type="xs:string">
<search:facet-value name="MarkLogic" count="38">MarkLogic</search:facet-value>
<search:facet-value name="Avalon Consulting, LLC" count="2">Avalon Consulting, LLC</search:facet-value>
<search:facet-value name="Overstory, Ltd." count="2">Overstory, Ltd.</search:facet-value>
<!--...-->
<search:facet name="rating" type="xs:int">
<search:facet-value name="5" count="61">5</search:facet-value>
<search:facet-value name="4" count="54">4</search:facet-value>
<search:facet-value name="3" count="34">3</search:facet-value>
<search:facet-value name="2" count="11">2</search:facet-value>
<search:facet-value name="1" count="2">1</search:facet-value>
<search:facet-value name="0" count="12">0</search:facet-value>
</search:facet>
<search:facet name="company" type="xs:string">
<search:facet-value name="MarkLogic" count="38">MarkLogic</search:facet-value>
<search:facet-value name="Avalon Consulting, LLC" count="2">Avalon Consulting, LLC</search:facet-value>
<search:facet-value name="Overstory, Ltd." count="2">Overstory, Ltd.</search:facet-value>
<!--...-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment