src/core/domain/dtos/elastic/es-multimatch.dto.ts
Elasticsearch multi-match query DTO
Properties |
constructor(query: string, fields: Array
|
|||||||||
Constructs a multi-match
Parameters :
|
Public Optional from |
Type : number
|
Decorators :
@IsOptional()
|
Offset from the start of the list of hits |
Private Readonly query |
Type : Object
|
Decorators :
@IsDefined()
|
The search query object passed to Elasticsearch |
Public Optional size |
Type : number
|
Decorators :
@IsOptional()
|
Maximum number of elements returned by Elasticsearch |
import { ApiExtraModels, ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsDefined, IsInt, IsObject, IsOptional } from "class-validator";
/**
* List of allowed properties in this DTO
*/
const allowedProperties = ['query'];
/**
* Elasticsearch multi-match query DTO
*/
@ApiExtraModels()
export class EsMultimatchQueryDto {
/**
* Offset from the start of the list of hits
*/
@IsOptional()
@IsInt()
@ApiPropertyOptional({
description: 'Offset from the start of the list of hits',
example: 5,
})
public from?: number;
/**
* Maximum number of elements returned by Elasticsearch
*/
@IsOptional()
@IsInt()
@ApiPropertyOptional({
description: 'Maximum number of elements returned by Elasticsearch',
example: 30
})
public size?: number;
/**
* The search query object passed to Elasticsearch
*/
@IsDefined()
@IsObject()
@ApiProperty({
description: 'Search query object passed to Elasticsearch',
example: {
multi_match: {
query: 'Maths',
fields: [
'title',
'content'
]
}
},
})
private readonly query: Object;
/**
* Constructs a multi-match
*/
constructor(query: string = '', fields: Array<string> = ['content']) {
this.query = {
multi_match: {
query: query,
fields: fields
}
}
}
}