11import { getDocDescriptor } from '../utils/index'
2- import { prepareGetParams } from '../utils/params'
2+ import { prepareGetParams , mergeESParamsWithRefresh } from '../utils/params'
33import { ElasticsearchServiceParams , ElasticAdapterInterface , DocDescriptor , IndexRequest } from '../types'
44import { get } from './get'
55
6- function getCreateParams ( service : ElasticAdapterInterface , docDescriptor : DocDescriptor ) : IndexRequest {
6+ function getCreateParams (
7+ service : ElasticAdapterInterface ,
8+ docDescriptor : DocDescriptor ,
9+ requestParams : ElasticsearchServiceParams = { }
10+ ) : IndexRequest {
711 let { id, parent, routing, join, doc } = docDescriptor
812
913 if ( join ) {
@@ -19,25 +23,25 @@ function getCreateParams(service: ElasticAdapterInterface, docDescriptor: DocDes
1923 }
2024
2125 // Build params with required fields
22- const params : IndexRequest = {
26+ const indexParams : IndexRequest = {
2327 index : service . index || '' ,
2428 document : doc
2529 }
2630
2731 // Only add id if it's defined
2832 if ( id !== undefined ) {
29- params . id = id
33+ indexParams . id = id
3034 }
3135
3236 // Only add routing if it's defined
3337 if ( routing !== undefined ) {
34- params . routing = routing
38+ indexParams . routing = routing
3539 }
3640
37- // Merge esParams but exclude index if it's already set
38- const cleanEsParams = service . esParams ? { ... service . esParams } : { }
39- delete ( cleanEsParams as Record < string , unknown > ) . index
40- return Object . assign ( params , cleanEsParams )
41+ // PERFORMANCE: Merge esParams with per-operation refresh override
42+ const cleanEsParams = mergeESParamsWithRefresh ( service . esParams , requestParams )
43+ delete cleanEsParams . index
44+ return Object . assign ( indexParams , cleanEsParams )
4145}
4246
4347export function create (
@@ -47,7 +51,7 @@ export function create(
4751) {
4852 const docDescriptor = getDocDescriptor ( service , data )
4953 const { id, routing } = docDescriptor
50- const createParams = getCreateParams ( service , docDescriptor )
54+ const createParams = getCreateParams ( service , docDescriptor , params )
5155 const getParams = prepareGetParams ( params , 'upsert' )
5256
5357 // If we have routing (parent document), pass it in the query for the get operation
0 commit comments