File

src/core/domain/dtos/elastic/es-multimatch.dto.ts

Description

Elasticsearch multi-match query DTO

Index

Properties
  • Public Optional from
  • Private Readonly query
  • Public Optional size

Constructor

constructor(query: string, fields: Array)

Constructs a multi-match

Parameters :
Name Type Optional
query string No
fields Array<string> No

Properties

Public Optional from
Type : number
Decorators :
@IsOptional()
@IsInt()
@ApiPropertyOptional({description: 'Offset from the start of the list of hits', example: 5})

Offset from the start of the list of hits

Private Readonly query
Type : Object
Decorators :
@IsDefined()
@IsObject()
@ApiProperty({description: 'Search query object passed to Elasticsearch', example: undefined})

The search query object passed to Elasticsearch

Public Optional size
Type : number
Decorators :
@IsOptional()
@IsInt()
@ApiPropertyOptional({description: 'Maximum number of elements returned by Elasticsearch', example: 30})

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
            }
        }
    }
 }

results matching ""

    No results matching ""