diff --git a/CHANGELOG.md b/CHANGELOG.md index c80b50b7..47a901f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.0.8 + +* fix update&delete documents that use `routing`, fixes [#235](https://github.com/cars10/elasticvue/issues/235) + ## 1.0.7 This release contains no changes to elasticvue itself. It is only done to fix build issues with the macos desktop diff --git a/src/composables/components/search/EditDocument.ts b/src/composables/components/search/EditDocument.ts index 7d712a54..b9dc929d 100644 --- a/src/composables/components/search/EditDocument.ts +++ b/src/composables/components/search/EditDocument.ts @@ -23,7 +23,8 @@ type ElasticsearchDocumentMeta = { _id?: string, _version?: number, _primary_term?: number, - _seq_no?: number + _seq_no?: number, + _routing?: string } export const useEditDocument = (props: EditDocumentProps, emit: any) => { @@ -61,7 +62,8 @@ export const useEditDocument = (props: EditDocumentProps, emit: any) => { _id: data.value._id, _version: data.value._version, _primary_term: data.value._primary_term, - _seq_no: data.value._seq_no + _seq_no: data.value._seq_no, + _routing: data.value._routing } } @@ -76,6 +78,7 @@ export const useEditDocument = (props: EditDocumentProps, emit: any) => { index: props._index, type: props._type, id: props._id, + routing: props._routing, params: document.value }, snackbarOptions: { body: t('search.edit_document.update.growl') } diff --git a/src/services/ElasticsearchAdapter.ts b/src/services/ElasticsearchAdapter.ts index 419c9aea..7ebfa1de 100644 --- a/src/services/ElasticsearchAdapter.ts +++ b/src/services/ElasticsearchAdapter.ts @@ -190,18 +190,28 @@ export default class ElasticsearchAdapter { return this.request('_nodes', 'GET') } - index ({ index, type, id, params }: { index: string, type: string, id: any, params: any }) { - return this.request(`${index}/${type}/${encodeURIComponent(id)}?refresh=true`, 'PUT', params) - } - - get ({ index, type, id, routing }: { index: string, type: string, id: any, routing: any }) { + index ({ index, type, id, routing, params }: { + index: string, + type: string, + id: any, + routing: string, + params: any + }) { + let path = `${index}/${type}/${encodeURIComponent(id)}?refresh=true` + if (routing) path += `&routing=${routing}` + return this.request(path, 'PUT', params) + } + + get ({ index, type, id, routing }: { index: string, type: string, id: any, routing?: string }) { const params: IndexGetArgs = {} if (routing) params.routing = routing return this.request(`${index}/${type}/${encodeURIComponent(id)}`, 'GET', params) } - delete ({ index, type, id }: { index: string, type: string, id: any }) { - return this.request(`${index}/${type}/${encodeURIComponent(id)}?refresh=true`, 'DELETE') + delete ({ index, type, id, routing }: { index: string, type: string, id: any, routing?: string }) { + let path = `${index}/${type}/${encodeURIComponent(id)}?refresh=true` + if (routing) path += `&routing=${routing}` + return this.request(path, 'DELETE') } search (params: object, searchIndex?: string | string[]) {