Map:
"mappings" : {
"tags" : {
"properties" : {
"name" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}
}
字符串
搜索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" ]
} ]
}
}
型
为什么我在下面的go代码中得到elastic: Error 400 (Bad Request): all shards failed [type=search_phase_execution_exception]
?
我的代码:
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))
}
型
谢谢
1条答案
按热度按时间fgw7neuy1#
在我的例子中,问题是创建的索引没有别名,所以我必须做的是:
1.停止logstash
1.删除旧索引
1.在开发工具上运行此命令为新索引创建别名
字符串
1.重新启动logstash