Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

API CQL to search for Strings in Confluence

Hi all,

 

I am trying to write something that will let me use the API to search for a given string throughout Confluence. 
For example if I want to search for the string 'testString' I can use:

http://<localhost>:8090/rest/api/content/search?cql=type=page+and+text~"testString"&expand=body.storage

This appears to work as expected and returns all spaces/pages with 'testString' in the body of the page.

However I want to search across other Confluence sources such as:

  • History - content of previous page versions
  • Comments
  • Attachments

It feels like this should be simple but try as I might I haven't been able to modify my existing query above to accommodate these other sources as the results are never found when I test it. 

Has anyone done this before? Suggestions would be most welcome.


Thanks very much!

2 answers

1 accepted

1 vote
Answer accepted

Hi Luke,

you are searching only on pages (type=page). Try leaving that parameter away:

http://<localhost>:8090/rest/api/content/search?cql=text~"testString"&expand=body.storage

This will search attachments, comments, pages & blogs. I'm pretty sure, that the page history cannot be searched.

You might want to extent the result to more than 25 hits, as it's limited to this by default.

Best

JP

Thank you Jan-Peter, thats just what I needed! I completely missed that I was still searching on pages.

As you say it doesn't seem to return 'history' values and I may have to leave that one for now but this gets me most of the way there. 

Thanks again, really appreciated,

Luke

Also worth noting that you ought to make sure when you are searching multiple keywords either by using a search with cql=text or cql=title then you should make sure there is a + between each of the keywords (replacing the space) in your search string and the whole string must be enclosed by double quotes. So any code used may mean you need to add a regex to .replace the space characters in your string with a +

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

🥓🙅🏻‍♀️ Meet-less May Badge!

Hello Confluence Community!  What if i told you that you could have a healthier life and be 100% meet-less? This month, we're promoting a healthy, balanced work diet with Confluence. We la...

223 views 2 14
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you