TUrwin
TUrwin

Reputation: 825

Setting up MarkLogic /suggest options (REST API)

new to MarkLogic and I'm having some trouble using the /suggest endpoint of the MarkLogic REST API.

I am trying to generate suggestions based on the 'name' attribute from all documents in my test database.

The documents look like this: app-prototype (3 Documents) | /gs/cobra.json

{
"name": "cobra", 
"kind": "mammal", 
"desc": "The cobra is a venomous, hooded snake of the family Elapidae."
}

Calling http://host:port/v1/suggest?partial-q=c, is always returning an empty set, and I suspect it's an issue with my search options/configuration.

Response:

{
    "suggestions": []
}

Using the following suggest-options.xml:

<options xmlns="http://marklogic.com/appservices/search">
    <default-suggestion-source>
    <range type="xs:string">
        <element ns="" name="name"/>
        <attribute ns="" name="name"/>
    </range>
    </default-suggestion-source>
</options>

and the following Attribute Range Index Configuration: Attribute Range Index

Unsure if I'm misunderstanding the use of namespaces/range indexes here.

Could anyone shed some light on what could be going wrong here?

EDIT: Replaced the index with an Element Range Index as follows: Element Range Index

and updated the default-suggestion-source to:

<options xmlns="http://marklogic.com/appservices/search">
    <default-suggestion-source>
        <range type="xs:string">
            <element ns="http://marklogic.com/xdmp/dls" name="name"/>
            <attribute ns="http://marklogic.com/xdmp/dls" name="name"/>
        </range>
    </default-suggestion-source>
</options>

Still no results returning.

Upvotes: 0

Views: 102

Answers (1)

grtjn
grtjn

Reputation: 20414

Your (JSON) documents do not contain name attributes, but name properties. Those are captured by element range indexes. Alternatively, you could also use a path range index on name. Replace the index, and adjust your default-suggestion-source accordingly.

Make sure though that the element range index uses an empty namespace uri. JSON properties are never in a namespace (which matches the behavior of elements in no namespace).

Also make sure to drop the <attribute ..> from the suggestion source, or it will still look for the attribute range index.

HTH!

Upvotes: 2

Related Questions