This is an automated email from the ASF dual-hosted git repository.

LinkinStars pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/answer-plugins.git

commit 5d51b35327836788349c137df8f7a004b4c5139f
Author: hgaol <[email protected]>
AuthorDate: Wed Jul 8 15:38:00 2026 +0000

    fix(elasticsearch): read index mapping via untyped endpoint for ES 8
    
    indexEmbeddingDims used the client's GetMapping helper, which targets the
    typed /_mapping/{type} endpoint removed in Elasticsearch 8, returning HTTP
    400 and breaking the plugin configuration update. Query the untyped
    GET /{index}/_mapping endpoint directly instead. Also make the dimension
    check best-effort so a mapping-read failure logs a warning and keeps the
    existing index rather than failing the whole config update.
---
 vector-search-elasticsearch/es.go | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/vector-search-elasticsearch/es.go 
b/vector-search-elasticsearch/es.go
index dd9561b..8dfef23 100644
--- a/vector-search-elasticsearch/es.go
+++ b/vector-search-elasticsearch/es.go
@@ -24,6 +24,7 @@ import (
        "embed"
        "encoding/json"
        "fmt"
+       "net/http"
        "strconv"
        "strings"
        "sync"
@@ -395,12 +396,13 @@ func (e *VectorSearchEngine) ensureIndex(ctx 
context.Context) error {
        if exists {
                // If the existing index's embedding dimensions differ from the
                // configured ones (e.g. the embedding model changed), delete 
it so it
-               // can be recreated with the new dimensions.
+               // can be recreated with the new dimensions. This is a 
best-effort
+               // check: if the mapping can't be read, keep the existing index 
rather
+               // than failing the whole configuration update.
                existingDims, err := e.indexEmbeddingDims(ctx)
                if err != nil {
-                       return fmt.Errorf("get index mapping: %w", err)
-               }
-               if existingDims > 0 && existingDims != dims {
+                       log.Warnf("es-vector: could not read index dimensions, 
keeping existing index: %v", err)
+               } else if existingDims > 0 && existingDims != dims {
                        log.Warnf("es-vector: dimensions changed from %d to %d, 
recreating index", existingDims, dims)
                        if _, err := e.client.DeleteIndex(indexName).Do(ctx); 
err != nil {
                                return fmt.Errorf("delete index for dimension 
change: %w", err)
@@ -437,11 +439,25 @@ func (e *VectorSearchEngine) ensureIndex(ctx 
context.Context) error {
 
 // indexEmbeddingDims returns the configured `dims` of the embedding field in 
the
 // existing index mapping, or 0 if it cannot be determined.
+//
+// It uses the untyped `GET /{index}/_mapping` endpoint directly rather than 
the
+// client's GetMapping helper, because that helper targets the typed
+// `/_mapping/{type}` endpoint which was removed in Elasticsearch 8 and returns
+// HTTP 400 there.
 func (e *VectorSearchEngine) indexEmbeddingDims(ctx context.Context) (int, 
error) {
-       m, err := e.client.GetMapping().Index(indexName).Do(ctx)
+       res, err := e.client.PerformRequest(ctx, elastic.PerformRequestOptions{
+               Method: http.MethodGet,
+               Path:   "/" + indexName + "/_mapping",
+       })
        if err != nil {
                return 0, err
        }
+
+       var m map[string]interface{}
+       if err := json.Unmarshal(res.Body, &m); err != nil {
+               return 0, err
+       }
+
        // Response shape:
        // { "<index>": { "mappings": { "properties": { "embedding": { "dims": 
N } } } } }
        idx, ok := m[indexName].(map[string]interface{})

Reply via email to