duanjiao1256 2017-07-28 17:41
浏览 391
已采纳

DeleteByQuery ElasticSearch Golang错误弹性:错误404(未找到)

I'm trying to delete the documents from my Index with specific productIDs.

Here's the sample code:

package main

import (
    "encoding/json"
    "log"
    "time"
    "fmt"
    "gopkg.in/mgo.v2/bson"
    elastic "gopkg.in/olivere/elastic.v3"
)

func main() {

    client, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetURL("http://localhost:9200"))
    if err != nil {
        log.Fatal("Cannot create ES client:", err)
    }
    boolQuery := elastic.NewBoolQuery().Must(elastic.NewTermQuery("productId", "1503368"))

    searchQuery := client.Search().Query(boolQuery).
        Index("magento1").Type("catalog")
    result, err := searchQuery.Do()
    for _, hit := range result.Hits.Hits {
        var data bson.M
        _ = json.Unmarshal(*hit.Source, &data)
        fmt.Println("SEARCH RESPONSE
", data)
    }

    result2, err2 := elastic.NewDeleteByQueryService(client).
        Index("magento1").
        Type("catalog").
        Query(boolQuery).
        Do()
    fmt.Println("DELETE RESPONSE 2: 
", result2, err2)

}

The SearchQuery gives the correct response and returns me the document with the provided productId (I DID THIS JUST TO VERIFY IF THE DOCUMENT EXISTS OR NOT).

Now the deletion, I don't know what on earth is wrong with the code or if there's anything missing in the API or something extra has to be added (matchAll etc) but this deleteQuery is just not deleting the Index and is always giving me the response:

error elastic: Error 404 (Not Found)

I've searched all the blogs/docs/official library's GitHub tests cases etc but none resolved my problem. Although I've come to a resolution to Scan/Scroll and Bulk delete still wonder why this is not working if it's in the official documentation.

Here's the mapping:

"productId": bson.M{"type": "string", "store": true, "index": "not_analyzed"},

ES VERSION: 5.3.1

Thanks.

  • 写回答

1条回答 默认 最新

  • dua6992 2017-07-29 04:10
    关注

    The issue comes from the fact that your using elastic.v3 which targets ES 2.x.

    Since you're using ES 5.3.1, you need to use elastic.v5, so simply replace this line

    elastic "gopkg.in/olivere/elastic.v3"
    

    by

    elastic "gopkg.in/olivere/elastic.v5"
    

    and you should be fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记