File

src/core/domain/dtos/es-response.dto.ts

Description

Elasticsearch response DTO

Index

Properties

Properties

_shards
Type : object
Decorators :
@IsOptional()
@IsObject()
@ApiProperty({description: '_shards', example: undefined})

Contains a number of Elasticsearch shards used for the request

hits
Type : object
Decorators :
@IsOptional()
@IsObject()
@ApiProperty({description: 'hits', example: undefined})

Contains returned documents and metadata

timed_out
Type : boolean
Decorators :
@IsDefined()
@IsNotEmpty()
@IsBoolean()
@ApiProperty({description: 'timed_out', example: false})

Status of the request If 'true' - the request timed out before completion

took
Type : number
Decorators :
@IsDefined()
@IsNotEmpty()
@IsNumber()
@ApiProperty({description: 'took', example: 5})

Number of milliseconds it took Elasticsearch to execute the request

import { ApiProperty } from "@nestjs/swagger";
import { IsBoolean, IsDefined, IsNotEmpty, IsNumber, IsObject, IsOptional } from "class-validator";

/**
 * List of allowed properties in this DTO
 */
const allowedProperties = ['took', 'timed_out', '_shards', 'hits'];

/**
 * Elasticsearch response DTO
 */
export class EsResponseDto {
    /**
     * Number of milliseconds it 
     * took Elasticsearch to execute the request 
     */
    @IsDefined()
    @IsNotEmpty()
    @IsNumber()
    @ApiProperty({
        description: 'took',
        example: 5
    })
    took: number;
    
    /**
     * Status of the request
     * If 'true' - the request timed out before completion
     */
    @IsDefined()
    @IsNotEmpty()
    @IsBoolean()
    @ApiProperty({
        description: 'timed_out',
        example: false,
    })
    timed_out: boolean;
    
    /**
     * Contains a number of Elasticsearch shards
     * used for the request
     */
    @IsOptional()
    @IsObject()
    @ApiProperty({
        description: '_shards',
        example: {
            total: 1,
            successful: 1,
            skipped: 0,
            failed: 0,
        }
    })
    _shards: object;

    /**
     * Contains returned documents and metadata
     */
    @IsOptional()
    @IsObject()
    @ApiProperty({
        description: 'hits',
        example: {
            total: {
                value: 3,
                relation: 'eq'
            },
            max_score: 1.2,
            hits: [{
                _index: 'papers',
                _id: '01002',
                _score: 1.2,
                _source: {

                },
                fields: {

                }
            }],
        }
    })
    hits: object;
}

results matching ""

    No results matching ""