dotCMS / dotCMS/core

API Query /api/es/search?depth=1, option to set related content language or have related content follow the languageId:

Open
#31,743 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type : New Functionality
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

Parent Issue

No response

User Story

As a backend user, I want to be able to create an API call that outputs a list of related items that has the same languageId as the parent content type and not all language versions so I can create websites that only show a single language.

Acceptance Criteria

Some form of acceptance criteria within the API Query that would allow for the related content language to either be specified or have it use the languageId set within the query.

Proposed Objective

User Experience

Proposed Priority

Priority 4 - Trivial

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

https://dotcms.freshdesk.com/a/tickets/30000

Assumptions & Initiation Needs

Currently, all related content gets printed regardless of the set languageId. An example of a query that does this would be.

`{
    "query": {
        "query_string": {
            "query": "+contentType:quoteContent +quoteContent.item:auto +languageId:1 +deleted:false +working:true"
        }
    }
}`

To replicate the situation encountered by the customer on my local instance,

  1. I created a piece of content with a related field called relatedFaqs.
  2. I then added a single related contentlet that contained some text in a field called "question".
  3. I then selected an additional language for the contentlet and filled it with different text.

After setting this up, I created the query in Postman using http://localhost:8082/api/es/search?depth=1, adjusting the contentType in the query to match my created content type. Finally, I added the Post-Response script from the workaround section of this ticket, just adjusting the {{#each section to

`                    {{#each relatedFaqs}}
                        <li>{{question}}</li>
                    {{/each}}`

and ran the query. This will show all relatedFaqs instead of just the languageId:1 versions.

Quality Assurance Notes & Workarounds

For the specific ticket mentioned, as a workaround I adjusted the post-response that outputs the information to have it set a variable to only the related contentlets that match the languageId in the query. Here is the full version of that Post-Response code.

`// Parse response data
let responseData = pm.response.json();

// Preprocess data: Add a filtered `matchingRelatedFaqs` array to each contentlet
responseData.contentlets.forEach(contentlet => {
    contentlet.matchingRelatedFaqs = contentlet.relatedFaqs.filter(faq => faq.languageId === contentlet.languageId);
});

var template = `
<style type="text/css">
    .tftable {font-size:14px;color:#333333;width:100%;border-width: 1px;border-color: #87ceeb;border-collapse: collapse;}
    .tftable th {font-size:18px;background-color:#87ceeb;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;text-align:left;}
    .tftable tr {background-color:#ffffff;}
    .tftable td {font-size:14px;border-width: 1px;padding: 8px;border-style: solid;border-color: #87ceeb;}
    .tftable tr:hover {background-color:#e0ffff;}
</style>

<table class="tftable" border="1">
    <tr>
        <th>Title</th>
        <th>Language ID</th>
        <th>Path</th>
        <th>Related FAQs</th>
    </tr>
    {{#each response.contentlets}}
        <tr>
            <td>{{title}}</td>
            <td>{{languageId}}</td>
            <td>{{path}}</td>
            <td>
                <ul>
                    {{#each matchingRelatedFaqs}}
                        <li>{{question}}</li>
                    {{/each}}
                </ul>
            </td>
        </tr>
    {{/each}}
</table>
`;

pm.visualizer.set(template, { response: responseData });`
Sub-Tasks & Estimates

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior with /api/es/search?depth=1 in Postman using the languageId and relatedFaqs setup described in the issue. Trace the API query handling and verify that related items can either receive an explicit language or follow the parent contentlet's languageId; done means the response excludes unrelated language versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
elasticsearch, java
Domain
api, backend, search
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.