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

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条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 关于#tensorflow#的问题,如何解决?
      • ¥15 VBA中使用FindWindowEx函数如何向网页表单中的多个文本框中的某一个文本框发送消息
      • ¥15 关于#glmb#的问题,如何解决?
      • ¥15 TI的TMS320F28335,RS485串口进行SCI-B通信出错
      • ¥15 XML文件报错不允许出现此特性,百度也搜不到解决方法
      • ¥15 FTPC共同交流学习
      • ¥15 关于#python#的问题:或者是我换其他什么模块可以解决这个问题图如下:
      • ¥15 用html加css制作一个网页
      • ¥200 MFC中如何对ListCtrl的某一列的文本能换行显示
      • ¥15 clion添加库文件