-
Notifications
You must be signed in to change notification settings - Fork 115
Closed as not planned
Closed as not planned
Copy link
Description
🐛 Bug Report
The function_score type in the QueryDslQueryContainer interface seems to be incorrect.
I implemented the first example from the Function score query docs in TypeScript:
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/api/types'
const query: QueryDslQueryContainer = {
function_score: {
query: { match_all: {} },
boost: 5,
random_score: {},
^^^^^^^^^^^^^^^^^
boost_mode: 'multiply',
},
}which results in the following type error:
(property) random_score: {}
Type '{ query: { match_all: {}; }; boost: number; random_score: {}; boost_mode: "multiply"; }' is not assignable to type 'QueryDslFunctionScoreQuery'.
Object literal may only specify known properties, and 'random_score' does not exist in type 'QueryDslFunctionScoreQuery'.
types.d.ts(4824, 3): The expected type comes from property 'function_score' which is declared here on type 'QueryDslQueryContainer'
Expected behavior
No type error should occur. I'm not familiar with the code base, the correct fix seems to change the function_score type in the QueryDslQueryContainer interface from
interface QueryDslQueryContainer {
function_score?: QueryDslFunctionScoreQuery
}to
interface QueryDslQueryContainer {
function_score?: QueryDslFunctionScoreQuery | QueryDslFunctionScoreContainer
}Hoping this is the correct solution, I went ahead and created a PR for this change: elastic/elasticsearch-js#1745
It's tested to be working with a running Elastic instance :-)
Your Environment
@elastic/elasticsearchversion: >=7.16.0
Metadata
Metadata
Assignees
Labels
No labels