-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.controller.ts
More file actions
55 lines (49 loc) · 1.27 KB
/
Copy pathsearch.controller.ts
File metadata and controls
55 lines (49 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
Query,
} from '@nestjs/common';
import { Article, SearchService } from './search.service';
/**
* Demo REST endpoints exercising the Elasticsearch integration.
* Adapt or remove for your real domain — this is reference material.
*/
@Controller('search')
export class SearchController {
constructor(private readonly search: SearchService) {}
/** GET /search/health → proves NestJS can reach localhost:9200. */
@Get('health')
health() {
return this.search.health();
}
/** POST /search/:index → index a document. */
@Post(':index')
async index(
@Param('index') index: string,
@Body() doc: Article,
): Promise<{ indexed: string }> {
await this.search.index(index, doc);
return { indexed: doc.id };
}
/** GET /search/:index?q=term → full-text search. */
@Get(':index')
find(
@Param('index') index: string,
@Query('q') q: string,
): Promise<Article[]> {
return this.search.search(index, q);
}
/** DELETE /search/:index/:id → remove a document. */
@Delete(':index/:id')
async remove(
@Param('index') index: string,
@Param('id') id: string,
): Promise<{ deleted: string }> {
await this.search.remove(index, id);
return { deleted: id };
}
}