0
votes

Can someone explain why OR (second one from the left) in original query (generated programmatically) becomes MUST in the parsed query? How do i prevent this?

Original Query: +matchAllDocs:true +( request_id:(00000000000000000000000000002796 OR 00000000000000000000000000002829) OR ( matchAllDocs:true AND ( request_id:(00000000000000000000000000002796) AND status_id:(1)) OR ( request_id:(00000000000000000000000000002829) AND status_id:(2))) AND (alltext:(internal) OR subject:(internal )^1.5))

Parsed Query: +matchAllDocs:true +((request_id:00000000000000000000000000002796 request_id:00000000000000000000000000002829) +(+matchAllDocs:true +(+request_id:00000000000000000000000000002796 +status_id:1) (+request_id:00000000000000000000000000002829 +status_id:2)) +(alltext:intern subject:intern^1.5))

Thanks

1

1 Answers

0
votes

Because AND beats OR (order of operation):

(something) OR //left will be SHOULD
(
    matchAllDocs:true AND 
    (
        request_id:(00000000000000000000000000002796) AND status_id:(1)
    ) OR 
    (
         request_id:(00000000000000000000000000002829) AND status_id:(2)
    )
) **AND** // left will be MUST
(alltext:(internal) OR subject:(internal )^1.5)

The solutions is to use more parenthesis, like so:

+matchAllDocs:true +((request_id:(00000000000000000000000000002796 OR 00000000000000000000000000002829) OR ( matchAllDocs:true AND ( request_id:(00000000000000000000000000002796) AND status_id:(1)) OR ( request_id:(00000000000000000000000000002829) AND status_id:(2)))) AND (alltext:(internal) OR subject:(internal )^1.5))