Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"canvas-element": "c27505dcf2970760bea8a0fe1d000253f0c40f08",
"canvas-workpad": "eb7b28a3b1c24af615edbf29becddf2e750a4bb5",
"canvas-workpad-template": "34454b811e32993eaa55c6ec85a7aecca00c4cfc",
"cases": "7ff5ce930146a2d6fc8fbf536ce2ee16e9df296f",
"cases": "a34407b3f348d4784e8c86b2a4ab3f4c7c042301",
"cases-comments": "d7c4c1d24e97620cd415e27e5eb7d5b5f2c5b461",
"cases-configure": "1afc414f5563a36e4612fa269193d3ed7277c7bd",
"cases-connector-mappings": "4b16d440af966e5d6e0fa33368bfa15d987a4b69",
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/cases/server/client/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ describe('utils', () => {
expect(sortToSnake('closed_at')).toBe('closed_at');
});

it('transforms title correctly', () => {
expect(sortToSnake('title')).toBe('title.keyword');
});

it('transforms default correctly', () => {
expect(sortToSnake('not-exist')).toBe('created_at');
});
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/cases/server/client/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ enum SortFieldCase {
closedAt = 'closed_at',
createdAt = 'created_at',
status = 'status',
title = 'title.keyword',
}

export const sortToSnake = (sortField: string | undefined): SortFieldCase => {
Expand All @@ -506,6 +507,8 @@ export const sortToSnake = (sortField: string | undefined): SortFieldCase => {
case 'closedAt':
case 'closed_at':
return SortFieldCase.closedAt;
case 'title':

@cnasikas cnasikas Dec 12, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind if you rename the function form sortToSnake to getSortField or similar? The function does not convert from camel case to snake case any more.

return SortFieldCase.title;
default:
return SortFieldCase.createdAt;
}
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/cases/server/saved_object_types/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ export const createCaseSavedObjectType = (
},
title: {
type: 'text',
fields: {
keyword: {
type: 'keyword',
ignore_above: 160,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove it (my mistake, I know 🙂 ) in case it will cause a migration if we change it. The backend validation is enough. @rudolf if we change the ignore_above in the future will it trigger a migration (reindex)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean having the default value for this field?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean remove the ignore_above: 160 entirely.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would always reindex if any key was removed from the mappings (like removing the ignore_above) or if updating the mappings of the existing index fails.

@cnasikas cnasikas Dec 12, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @rudolf! What I meant is if we changing the ignore_above value from 160 to 200 will trigger a migration? I am just curious 🙂. We will not add it (never had it before this PR) so we do not have this dilemma in the future.

},
},
},
status: {
type: 'keyword',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,24 @@ export default ({ getService }: FtrProviderContext): void => {
}
});

it('sorts by title', async () => {
const case3 = await createCase(supertest, { ...postCaseReq, title: 'c' });
const case2 = await createCase(supertest, { ...postCaseReq, title: 'b' });
const case1 = await createCase(supertest, { ...postCaseReq, title: 'a' });

const cases = await findCases({
supertest,
query: { sortField: 'title', sortOrder: 'asc' },
});

expect(cases).to.eql({
...findCasesResp,
total: 3,
cases: [case1, case2, case3],
count_open_cases: 3,
});
});

it('unhappy path - 400s when bad query supplied', async () => {
await findCases({ supertest, query: { perPage: true }, expectedHttpCode: 400 });
});
Expand Down