manhtc
manhtc

Reputation: 45

How to search nodes (documents) matching with a range of conditions in MarkLogic by XCC

I am a newbie in MarkLogic, so please help me to find a solution.

My XML data are imported in to MarkLogic, and I want to find documents (nodes) with a specific range condition using XCC. I run below search command, but get an error. Please tell me what I was wrong and show me the solution. Thank you.

cts:search(fn:doc(),
  cts:and-query(cts:element-range-query(xs:QName("RequestDatetime"), ">=", "20141102170000"), 
  cts:element-range-query(xs:QName("RequestDatetime"), "<=", "20141103170000"))

Error contents is

[1.0-ml] XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected UnterminatedComment_, expecting Function30_ or Percent_

Hi wst and other

I tried to create element-range-index, but it seems not to be working. My data contains many XML file with the format as below. Now If I want to seach range for the Element of RequestDatetime , what I have to do?

Thank you

<?xml version="1.0" encoding="UTF-8"?>
<Request>
    <RequestDatetime>
        20141102174108
    </RequestDatetime>
    <RemoteHostName>
        xxxx.xxxx.xxxx.xxxx
    </RemoteHostName>
    <OrgRequest>
       GET http://xxxx/ HTTP/1.1
    </OrgRequest>
    <Protocol>
        xxxx
    </Protocol>
    <WebServer>
        xxxxxxxxx
    </WebServer>
    <Request>
        xxxxxxxxxxx
    </Request>
    <StatusCode>
    xxxxxxx
    </StatusCode>
    <BytesSent>
        Xxxxxxxxxx
    </BytesSent>
    <UserAgent>
    </UserAgent>
    <RemoteLogName>
    </RemoteLogName>
    <Cookie>
    </Cookie>
    <Referer>
    </Referer>
    <UserName>
    </UserName>
</Request>

Upvotes: 2

Views: 317

Answers (1)

wst
wst

Reputation: 11771

The cts:queries passed to cts:and-query are a sequence, so they need to be enclosed in parens (unlike fn:concat()):

cts:search(fn:doc(),
  cts:and-query((
    cts:element-range-query(xs:QName("RequestDatetime"), ">=", "20141102170000"), 
    cts:element-range-query(xs:QName("RequestDatetime"), "<=", "20141103170000")
  ))
)

Upvotes: 2

Related Questions