'elastic: Error 400 (Bad Request): all shards failed [type=search_phase_execution_exception]

Mappings:

    "mappings" : {
  "tags" : {
    "properties" : {
      "name" : {
        "type" : "string",
        "index" : "not_analyzed"
      }
    }
  }
}

Search in es:

curl -XGET "http://localhost:16683/ditto-tags/_search?pretty" -d'{ "query": { "bool": {"should": [ {"fuzzy": {"name": "cpwi"}}, {"prefix": {"name": "cpwi"}}, {"match": {"name": {"query": "cpwi", "boost": 2}}} ]} }, "sort": [ "_score", {"name": "asc"} ] }'
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : null,
    "hits" : [ {
      "_index" : "ditto-tags",
      "_type" : "tags",
      "_id" : "cpwi",
      "_score" : 12.336254,
      "_source" : {
        "name" : "cpwi"
      },
      "sort" : [ 12.336254, "cpwi" ]
    } ]
  }
}

Why I got elastic: Error 400 (Bad Request): all shards failed [type=search_phase_execution_exception] in the following go codes?

My codes:

p.Logger.Info("Elasticsearch Gateway searchTag")
template := `{
        "query": {
            "bool": {"should": [
                {"fuzzy": {"name": "%s"}},
                {"prefix": {"name": "%s"}},
                {"match": {"name": {"query": "%s", "boost": 2}}}
            ]}
        },
        "sort": [
            "_score",
            {"name": "asc"}
        ]
    }`
s := fmt.Sprintf(template, queryString, queryString, queryString)
searchResult, err := esClient.Search().
    Index("tags").
    Query(es.NewRawStringQuery(s)). // specify the query
    Pretty(true).                   // pretty print request and response JSON
    Do(context.Background())        // execute
if err != nil {
    // Handle error
    p.Logger.Error("Failed to search tags", zap.String("query", s), zap.Error(err))
} 

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source