Loading TOC...


   model as Object
) as element(search.options)


This function is deprecated and will not be supported in MarkLogic 11.
Generate a set of query options that can be used to query your entity instances using several MarkLogic server-side and client APIs.

model A valid basic entity model.

Usage Notes

The generated query options can be used to query your entity instances using the XQuery Search API, the Server-Side JavaScript JSearch API, or the REST, Java, or Node.js Client APIs. For example, you can use the output of this function in a combined query passed through the REST, Java, or Node.js Client APIs.

You can use the options as-is or customize them. As-is, the options include several constraints and potentially useful default behavior. For example, the options include a constraint named entity-type that differentiates among the various entity types in the model. The options also leverage lexicon and range index definitions in the basic model. The options include the following:

See Also


// Generate query options from a basic model.
const es = require('/MarkLogic/entity-services/entity-services');
es.searchOptionsGenerate( es.modelValidate(
{ "info": { 
    "title": "Example", 
    "description": "ES Examples",
    "version": "1.0.0",
  "definitions": {
    "Name" : {
      "properties": {
        "first": { "datatype": "string" },
        "middle": { "datatype": "string" },
        "last": { "datatype": "string" }
      "required": ["first", "last"]
    "Person": {
      "properties": {
        "id": { "datatype": "int" },
        "name": { 
          "$ref": "#/definitions/Name", 
        "bio": { "datatype": "string" },
        "rating": { "datatype": "float" },
        "phone": {
          "datatype": "array",
          "items": { "datatype": "string"}
        "friend": {
          "datatype" : "array",
          "items": { "$ref" : "#/definitions/Person" }
      "required": ["id", "name"],
      "primaryKey" : "id",
      "rangeIndex": ["rating"],
      "wordLexicon": ["bio"]

/* Result: XML Query options similar to the following, usable with the 
 * XQuery Search API and the REST, Node.js, and Java Client APIs.
<search:options xmlns:search="http://marklogic.com/appservices/search">
  <search:constraint name="entity-type">
      <search:element ns="http://marklogic.com/entity-services" name="title"/>
  <search:constraint name="id">
      <search:element ns="" name="id"/>
  <search:constraint name="rating">
    <search:range type="xs:float" facet="true">
      <search:path-index xmlns:es="http://marklogic.com/entity-services">
  <search:constraint name="bio">
      <search:element ns="" name="bio"/>
  <search:tuples name="Person">
    <search:range type="xs:float" facet="true">
      <search:path-index xmlns:es="http://marklogic.com/entity-services">
  <!--Uncomment to return no results for a blank search, rather than the default of all results
  <search:term xmlns:search="http://marklogic.com/appservices/search">
    <search:empty apply="no-results"/>
  <search:values name="uris">
  <!--Change to 'filtered' to exclude false-positives in certain searches-->
  <!--Modify document extraction to change results returned-->
  <search:extract-document-data selected="include">
    <search:extract-path xmlns:es="http://marklogic.com/entity-services">
  <!--Change or remove this additional-query to broaden search beyond entity instance documents-->
    <cts:element-query xmlns:cts="http://marklogic.com/cts">
      <cts:element xmlns:es="http://marklogic.com/entity-services">
  <!--To return facets, change this option to 'true' and edit constraints-->
  <!--To return snippets, comment out or remove this option-->
  <search:transform-results apply="empty-snippet"/>

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.