How to search for an exact literal text match using API calls without the public REST API

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

    

Please be aware this uses an internal API that is not supported by Atlassian and is subject to change. The steps to potentially update this in the future are also included below.

tip/resting Created with Sketch.

There is a public feature request CONFSERVER-61268 - Allow for literal text-string matches using the REST API CQL search endpoint which is available to watch and vote on to be notified of any future updates.


Summary

It's possible to perform exact text matches using our advanced search in the UI by enclosing the search terms in quotation marks. However, using our API search endpoints does not allow for exact/literal string matches on text fields with the Lucene engine. The CQL text search only allows the ~ & !~ contains/does not contain operators as indicated in our CQL Field Reference for text.

Literal match using the UI - technically 'this' is an excluded word but does not affect the results of this method.

Diagnosis

As an example, these endpoints will find all page with those words in any order and they are the only available public REST API endpoints for searching text fields:

GET /rest/api/content/search?cql=text~"This sentence exact widget"
GET /rest/api/search?cql=text~"sentence widget been"


Example page:

Correct match as expected in the UI and also correct from the API call - search terms 'this exact sentence:'

cURL response finding an exact matching result pulled from the UI advanced search
Reply

"start": 0,
    "limit": 25,
    "size": 1,
    "totalSize": 1,


Incorrect match as expected in the UI  and also incorrect from the API call - search terms 'this sentence exact:
(info) Only swapped the order of the words.

cURL response finding zero results like the UI for the string: 'This sentence exact''
Reply

"start": 0,
    "limit": 25,
    "size": 0,
    "totalSize": 0,


Solution

We need to perform an exact match search in the UI and capture it so we can then modify it with your browser's developer tools.

  1. Open your browser developer tools and in most vendors look for the network tab.



  2. Perform an advanced search from the Confluence UI for an exact match with quotation marks.
  3. Grab the URL passed in the network tab from the cqlSearch request and copy and paste it to a text editor.


  4. It should look like the following:

    Internal API call for an exact match - look for 'SEARCH+TERMS+HERE'
    <baseURL>/rest/searchv3/1.0/cqlSearch?user=<username>&sessionUuid=<sessionID>&cql=siteSearch+~+%22%5C%22SEARCH+TERMS+HERE%5C%22%22&start=0&limit=10&excerpt=highlight&includeArchivedSpaces=false
  5. Then you can just update the search term you find in there along with any other parameters and make a cURL request. 

    cURL request for exact match text search
    curl --user <user>:<pass> --location --request GET <baseURL>/rest/searchv3/1.0/cqlSearch?user=<username>&sessionUuid=<sessionID>&cql=siteSearch+~+%22%5C%22SEARCH+TERMS+HERE%5C%22%22&start=0&limit=10&excerpt=highlight&includeArchivedSpaces=false
  • With a matching result that is only true for exact word matches - excluding already ignored dictionary words:

    ...siteSearch+~+%22%5C%22this+exact+sentence%5C%22%22...
    
       "start": 0,
        "limit": 25,
        "size": 1,
        "totalSize": 1,
        "cqlQuery": "siteSearch ~ \"\\\"this exact sentence\\\"\" and type in (\"space\",\"user\",\"page\",\"blogpost\",\"comment\")",

Last modified on Mar 2, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.