- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在尝试让 ElasticSearch 为我的自动完成服务索引内容,使用 v1.4x 中的 Completion Suggesters。我听从了 ElasticSearch - You Complete Me 的建议并且正在使用 Go 客户端 olivere/elastic .
我的索引方法看起来有点像这样:
func IndexVehicle(client *elastic.Client, vehicle Vehicle) (bool, error) {
// See if it exists already
fetch, err := client.Get().
Index(vehicleIndex).
Type("vehicle").
Id(vehicle.Id).
Do()
if err != nil || fetch.Found {
return false, err
}
vehicleName := fmt.Sprintf("%s %s (%s) %s", vehicle.Make, vehicle.Model, vehicle.Model_year, vehicle.Primary_fuel)
suggest := elastic.NewSuggestField()
suggest.Input(vehicle.Make, vehicle.Model, vehicle.Primary_fuel, vehicle.Model_year).
Output(vehicleName).
Payload(vehicle)
// Go forth and save
put, err := client.Index().
Index(vehicleIndex).
Type("vehicle").
Id(vehicle.Id).
Debug(true).Pretty(true).
BodyJson(indexBody{Name: vehicleName, Suggest: suggest}).
Do()
if err != nil {
return false, err
}
return put.Created, nil
}
现在奇怪的是,在我的一些测试中,这个方法运行良好,并且项目将被索引。在删除和重建索引后的其他测试中,测试将失败:
早期的测试在调试中是这样的:
2014/12/15 14:11:37 PUT /vehicle/vehicle/369f96459b340507c4688740da3bfe1a?pretty=true HTTP/1.1
Host: localhost:9200
User-Agent: elastic/1.3.1 (darwin-amd64)
Transfer-Encoding: chunked
Accept: application/json
Content-Type: application/json
Accept-Encoding: gzip
{"name":"American Motors Corporation Eagle 4WD (1986) regular","suggest":{"input":["American Motors Corporation","Eagle 4WD","regular","1986"],"output":"American Motors Corporation Eagle 4WD (1986) regular","payload":{"make":"American Motors Corporation","model_year":"1986","model":"Eagle 4WD","primary_fuel":"regular","vehicle_class":"Special Purpose Vehicle 4WD","transmission":"Automatic 3-spd","displacement":"4.2","drive":"4-Wheel or All-Wheel Drive","city_mpg":"15.0","highway_mpg":"19.0","comb_mpg":"17.0"}}}
2014/12/15 14:11:37 HTTP/1.1 201 Created
Content-Length: 134
Content-Type: application/json; charset=UTF-8
{
"_index" : "vehicle",
"_type" : "vehicle",
"_id" : "369f96459b340507c4688740da3bfe1a",
"_version" : 1,
"created" : true
}
但是在以后的测试中,做同样的事情会导致错误。后面的测试中IndexVehicle()
返回的err
是:
E
Errors:
* /Users/phil/go/src/github.com/ride/autocomplete/vehicle_test.go
Line 79: - elastic: Error 400: ElasticsearchIllegalArgumentException[No feature for name [vehicle]]
goroutine 245 [running]:
github.com/ride/autocomplete.func·033()
/Users/phil/go/src/github.com/ride/autocomplete/vehicle_test.go:79 +0x249
github.com/ride/autocomplete.useIndex(0x499e98)
/Users/phil/go/src/github.com/ride/autocomplete/test_helper.go:18 +0x55
github.com/ride/autocomplete.func·034()
/Users/phil/go/src/github.com/ride/autocomplete/vehicle_test.go:96 +0x2a
github.com/jtolds/gls._m(0x0, 0xc2080ae9e0)
/Users/phil/go/src/github.com/jtolds/gls/stack_tags.go:70 +0x32
github.com/jtolds/gls.markS(0x0, 0xc2080ae9e0)
/Users/phil/go/src/github.com/jtolds/gls/stack_tags.go:21 +0x32
github.com/jtolds/gls.addStackTag(0x0, 0xc2080ae9e0)
/Users/phil/go/src/github.com/jtolds/gls/stack_tags.go:18 +0x3e
github.com/jtolds/gls.(*ContextManager).SetValues(0xc20801e080, 0xc2080b31d0, 0xc2080ae9e0)
/Users/phil/go/src/github.com/jtolds/gls/context.go:98 +0x503
github.com/ride/autocomplete.TestSearchForVehicles(0xc20806a480)
/Users/phil/go/src/github.com/ride/autocomplete/vehicle_test.go:97 +0x243
testing.tRunner(0xc20806a480, 0x5be890)
/opt/boxen/homebrew/Cellar/go/1.4/libexec/src/testing/testing.go:447 +0xbf
created by testing.RunTests
/opt/boxen/homebrew/Cellar/go/1.4/libexec/src/testing/testing.go:555 +0xa8b
goroutine 1 [chan receive]:
testing.RunTests(0x49a078, 0x5be800, 0x7, 0x7, 0x67c001)
/opt/boxen/homebrew/Cellar/go/1.4/libexec/src/testing/testing.go:556 +0xad6
testing.(*M).Run(0xc2080463c0, 0x5c9b20)
/opt/boxen/homebrew/Cellar/go/1.4/libexec/src/testing/testing.go:485 +0x6c
main.main()
github.com/ride/autocomplete/_test/_testmain.go:64 +0x1d5
goroutine 208 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc208106d40)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
goroutine 248 [runnable]:
net/http.(*persistConn).readLoop(0xc20802e4d0)
/opt/boxen/homebrew/Cellar/go/1.4/libexec/src/net/http/transport.go:928 +0x9ce
created by net/http.(*Transport).dialConn
/opt/boxen/homebrew/Cellar/go/1.4/libexec/src/net/http/transport.go:660 +0xc9f
goroutine 98 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc208033e00)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/opt/boxen/homebrew/Cellar/go/1.4/libexec/src/runtime/asm_amd64.s:2232 +0x1
goroutine 44 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc2080332c0)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
goroutine 249 [select]:
net/http.(*persistConn).writeLoop(0xc20802e4d0)
/opt/boxen/homebrew/Cellar/go/1.4/libexec/src/net/http/transport.go:945 +0x41d
created by net/http.(*Transport).dialConn
/opt/boxen/homebrew/Cellar/go/1.4/libexec/src/net/http/transport.go:661 +0xcbc
goroutine 54 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc208032f80)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
goroutine 76 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc208032e00)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
goroutine 250 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc208106c40)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
goroutine 120 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc208106b00)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
goroutine 142 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc208106e00)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
goroutine 164 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc208106b80)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
goroutine 186 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc208106d00)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
goroutine 230 [chan receive]:
github.com/olivere/elastic.(*Client).pinger(0xc208106dc0)
/Users/phil/go/src/github.com/olivere/elastic/client.go:79 +0x6b
created by github.com/olivere/elastic.NewClient
/Users/phil/go/src/github.com/olivere/elastic/client.go:60 +0x26e
可能该回溯中更重要的部分是:
Error 400: ElasticsearchIllegalArgumentException[No feature for name [vehicle]]
所以,不确定这里到底出了什么问题。我的索引有 1 秒超时,因为这个客户端不支持“等待绿色”逻辑 [还]。
func ResetVehicleIndex(client *elastic.Client) (err error) {
if _, err = client.DeleteIndex(vehicleIndex).Do(); err != nil {
return
}
if _, err = EnsureVehicleIndex(client); err != nil {
return
}
// TODO: This is awful. Switch to "wait for green" when elastic client supports it
time.Sleep(time.Second * 1)
return nil
}
这对大多数其他测试都有效,因为 elasticsearch 似乎在一秒钟左右就可以准备好,但是无论那段代码中的等待时间如何,这些测试都会一直出错。
有什么想法吗?我可能需要编辑问题以添加更多代码或更好的解释,但我会非常快速地回复任何问题,尤其是如果您在 Twitter 上联系我 @philsturgeon .我真的被困在这上面了。
最佳答案
这个异常(exception)是 only triggered in one place ,这是在获取索引 API 调用期间。这意味着您的车辆 ID 在此处必须为空:
fetch, err := client.Get().
Index(vehicleIndex).
Type("vehicle").
Id(vehicle.Id). //<-- this
Do()
您正在尝试执行 Get Document API,其格式为 GET/{index}/{type}/{id}
。但是,您的客户端不会区分 Get Document 和 Get Index API 调用...并且它不会验证您的参数是否为非空。
因此,如果将 null vehicle.Id
传递给 Get 方法,您的最终 URL 实际上将是 GET/{index}/{type}/
从 Elasticsearch 的角度来看,这不再是 Get Document API 调用...实际上是 Get Index 调用,格式如下:GET/{index}/{feature}
.特征可以是以下之一:_settings
、_mappings
、_aliases
或 _warmers
。
因为 vehicle
不是这些功能之一,所以 ES 抛出异常并喷涌而出。您可以从控制台验证这一点:
curl -XGET localhost:9200/my_index/vehicle/
关于go - Elasticsearch + 去 : Index failures (No feature for name),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27491738/
我在这里有一个问题,我不知道这是否正常。 但是我认为这里有些湖,安装插件elasticsearch-head之后,我在浏览器中启动url“http://localhost:9200/_plugin/h
我写了这个 flex 搜索查询: es.search(index=['ind1'],doc_type=['doc']) 我得到以下结果: {'_shards': {'failed': 0, 'skip
在ElasticSearch.Net v.5中,存在一个属性 Elasticsearch.Net.RequestData.Path ,该属性在ElasticSearch.Net v.6中已成为depr
如何让 elasticsearch 应用新配置?我更改了文件 ~ES_HOME/config/elasticsearch.yml 中的一个字符串: # Disable HTTP completely:
我正在尝试使用以下分析器在 elastic serach 7.1 中实现部分子字符串搜索 PUT my_index-001 { "settings": { "analysis": {
假设一个 elasticsearch 服务器在很短的时间内接收到 100 个任务。有些任务很短,有些任务很耗时,有些任务是删除任务,有些是插入和搜索查询。 elasticsearch 是如何决定先运行
我需要根据日期过滤一组值(在此处添加字段),然后按 device_id 对其进行分组。所以我正在使用以下东西: { "aggs":{ "dates_between":{ "fi
我在 Elasticsearch 中有一个企业索引。索引中的每个文档代表一个业务,每个业务都有business_hours。我试图允许使用星期几和时间过滤营业时间。例如,我们希望能够进行过滤,以显示我
我有一个这样的过滤查询 query: { filtered: { query: { bool: { should: [{multi_match: {
Elasticsearch 相当新,所以可能不得不忍受我,我遇到了一个问题,如果我使用 20 个字符或更少的字符搜索文档,文档会出现,但是查询中同一个单词中的任何更多字符,我没有结果: 使用“苯氧甲基
我试图更好地理解 ElasticSearch 的内部结构,所以我想知道 ElasticSearch 在内部计算以下两种情况的术语统计信息的方式是否存在任何差异。 第一种情况是当我有这样的文件时: {
在我的 elasticsearch 索引中,我索引了一堆工作。为简单起见,我们只说它们是一堆职位。当人们在我的搜索引擎中输入职位时,我想“自动完成”可能的匹配。 我在这里调查了完成建议:http://
我在很多映射中使用多字段。在 Elastic Search 的文档中,指示应将多字段替换为“fields”参数。参见 http://www.elasticsearch.org/guide/en/ela
我有如下查询, query = { "query": {"query_string": {"query": "%s" % q}}, "filter":{"ids
我有一个Json数据 "hits": [ { "_index": "outboxprov1", "_type": "deleted-c
这可能是一个初学者的问题,但我对大小有一些疑问。 根据 Elasticsearch 规范,大小的最大值可以是 10000,我想在下面验证我的理解: 示例查询: GET testindex-2016.0
我在 Elastic Search 中发现了滚动功能,这看起来非常有趣。看了那么多文档,下面的问题我还是不清楚。 如果偏移量已经存在那么为什么要使用滚动? 即将到来的记录呢?假设它完成了所有数据的滚动
我有以下基于注释的 Elasticsearch 配置,我已将索引设置为不被分析,因为我不希望这些字段被标记化: @Document(indexName = "abc", type = "efg
我正在尝试在单个索引中创建多个类型。例如,我试图在host索引中创建两种类型(post,ytb),以便在它们之间创建父子关系。 PUT /ytb { "mappings": { "po
我尝试创建一个简单的模板,包括一些动态模板,但我似乎无法为文档编制索引。 我得到错误: 400 {"error":"MapperParsingException[mapping [_default_]
我是一名优秀的程序员,十分优秀!