Search API parameters

Hi guys!

Have a question regarding the search API - we are using Discourse for this crowdsourcing project: Amnesty Decoders

Basically, thousands of people from around the world are helping Amnesty International digitise documents that are hand written. Each of them does a simple task - at the end of the task, they can ask a question or make comments on a Discourse instance. Each task is done by multiple users so we can have more than one comment to a thread which is opened the first time someone comments a task.

We are having some problems with it now and hope you can help.

To post a reply to an existing task, we are using the search API. Basically, when someone posts a comment (we call it ‘flag’), it looks if anyone else commented the same task - if not, it creates a new topic; if yes, it replies to the the topic that has already been created by the first poster.

The problem is that the search of topic sometimes returns random topics… so users end up answering to old, completely unrelated conversations…

Is there any parameter to the search API that returns the exact topic, as opposed to the approximate one

Or do you have any ideas on how we could fix this problem?

Would really appreciate your answers!



When you create the topic for the first “flag” you don’t store the topic id?

Also, if you store / have a specific format for the title, you don’t need to use the search too, for example this topic resolves properly without the ID on the URL:


Hey @Falco, you linked to this same conversation?

Yes, if you have the slug (or the title, from which you can derive the slug) you have enough to find a topic.

I’m just not getting why you use the search in this use case, because saving the topic id would be the best topic canonical reference.


I see, so you are suggesting to search for ‘topic-slug’ instead of topic-id?

I am not a developer, I lead the project and am super frustrated that this is not working for users.

I think this is the call we make to the API:

as far as I understand, the only parameter of the search API is term… are we doing something wrong?

1 Like

The topic id is preferable but you make sound like you are not saving the topic id. Given that you don’t have the topic id (which would obviate searching), if your topics have unique names, you can just access the slug (as @falco’s example that points to this topic using the title /slug).


is there any way to specify what kind of ‘term’ we are looking for? whether it’s part of a ‘topic-slug’, a ‘topic-id’ or anything else?

And thanks so much @pfaffman and @Falco! This is extremely helpful - we spent few days working on this and it keeps throwing bugs at us…

The way you are approaching the problem is the problem.

The first time you create a new topic, you must save the topic ID. Next time you need to direct a user to this topic, just use the same ID to create a new post.


Thanks @Falco. The problem is now that we have a Discourse instance full of existing topics and we want to allow users to reply to those…is there any search query we can run to see if the topic-slug already exists?

The only thing you have stored is the topic slug?

If that’s the case a GET request to will return 301 for an existing topic and 404 for one that don’t exists yet.


Thanks! I am not sure we store the topic id… might be that we have to use the slug… Thanks so much!!!

I signed up so that I could take a look. What you are doing looks great! This is a very interesting use of Discourse.

It looks like you are using the same pattern to create all the topic titles, with the asset_id as the unique element in each title. @Falco’s approach should be able to work for you:


This is amazing! I signed up but it doesn’t look like discourse.

1 Like

Hi @RBoy, We use discourse for the discussion page , the other bit of the platform is on Hive a crowdsourcing platform from NYT

this is the discourse part: