Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on updating a previously created index #908

Open
manelio opened this issue Jul 19, 2023 · 2 comments
Open

Error on updating a previously created index #908

manelio opened this issue Jul 19, 2023 · 2 comments

Comments

@manelio
Copy link

manelio commented Jul 19, 2023

I receive a 'index [product] already exists' error when trying to update an index.

Version: Zinc 0.4.7, dockerized

Here's a simple and self-explanatory code to reproduce the problem:

import axios from 'axios'

const api = axios.create({
  baseURL: 'http://zincsearch:4080/api/',
  auth: {
    username: process.env.ZINC_FIRST_ADMIN_USER,
    password: process.env.ZINC_FIRST_ADMIN_PASSWORD,
  }
})

const data = {
  "name": "product",
  "storage_type": "disk",
  "shard_num": 1,
  "mappings": {
    "properties": {
      "name": {
        "type": "text",
        "index": true,
        "store": true,
        "highlightable": true
      },
    }
  }
}

// First call works as expected

await api({
  method: 'put',
  url: 'index',
  data: data,
})

// Second call fails with error `index [product] already exists`

await api({
  method: 'put',
  url: 'index',
  data: data,
})

// Also fails passing the index id in url

await api({
  method: 'put',
  url: 'index/product',
  data: data,
})
@manelio
Copy link
Author

manelio commented Jul 29, 2023

The same happens with mappings. Looking at the code looks like there's no way to update mappings, only creating new ones:

func SetMapping(c *gin.Context) {
  // ...
  // check if mapping field is exists
  if exists {
    indexMappings := index.GetMappings()
    if indexMappings != nil && indexMappings.Len() > 0 {
      for field := range mappings.ListProperty() {
        if _, ok := indexMappings.GetProperty(field); ok {
          zutils.GinRenderJSON(c, http.StatusBadRequest, meta.HTTPResponseError{Error: "index [" + indexName + "] already exists mapping of field [" + field + "]"})
          return
        }
      }
    }
import axios from 'axios'

const api = axios.create({
  baseURL: 'http://zincsearch:4080/',
  auth: {
    username: process.env.ZINC_FIRST_ADMIN_USER,
    password: process.env.ZINC_FIRST_ADMIN_PASSWORD,
  }
})

const data = {
  properties: {
    name: {
      type: "text",
      index: true,
      store: true,
    },
  }

}

await api({
  method: 'put',
  url: 'api/product/_mapping',
  data: data,
})

// Throws an error because 'name' mappings alredy exists

await api({
  method: 'put',
  url: 'api/product/_mapping',
  data: data,
})

Thanks for the effort to create this tool and I wish you luck, but for now it seems too unstable for the use I am looking for and I will switch to an alternative search engine.

@MyWay
Copy link

MyWay commented Mar 2, 2024

any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants