elasticsearch-error-notes

(1) index_not_found_exception

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"error": {
"root_cause": [
{
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_or_alias",
"resource.id": "test_20181204",
"index_uuid": "_na_",
"index": "test_20181204"
}
],
"type": "index_not_found_exception",
"reason": "no such index",
"resource.type": "index_or_alias",
"resource.id": "test_20181204",
"index_uuid": "_na_",
"index": "test_20181204"
},
"status": 404
}

问题原因: 没有对应索引

可能是没创建,可能是创建了被删除了

创建对应的索引即可

(2) illegal_argument_exception Fielddata is disabled on text fields by default

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$ curl -X GET "localhost:9200/megacorp/employee/_search" -H 'Content-Type: application/json' -d'
{
"aggs": {
"all_interests": {
"terms": { "field": "interests" }
}
}
}
'
{
"error":{
"root_cause":[
{
"type":"illegal_argument_exception",
"reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [interests] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
],
"type":"search_phase_execution_exception",
"reason":"all shards failed",
"phase":"query",
"grouped":true,
"failed_shards":[
{
"shard":0,
"index":"megacorp",
"node":"gjy4N2RCQ4mLxp1lxdyZ8w",
"reason":{
"type":"illegal_argument_exception",
"reason":"Fielddata is disabled on text fields by default. Set fielddata=true on [interests] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
]
},
"status":400
}

解决办法:

5.x后对排序,聚合这些操作用单独的数据结构(fielddata)缓存到内存里了,需要单独开启,官方解释在此 fielddata
简单来说就是修改如下配置

1
2
3
4
5
6
7
8
9
10
11
$ curl -X PUT "localhost:9200/megacorp/_mapping/employee/" -H 'Content-Type: application/json' -d'
{
"properties": {
"interests": {
"type": "text",
"fielddata": true
}
}
}
'
{"acknowledged":true}

(3) remote_transport_exception illegal_argument_exception

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$ curl -X POST "localhost:9200/website/blog/1/_update?pretty" -H 'Content-Type: application/json' -d'
> {
> "script" : "ctx._source.tags+=new_tag",
> "params" : {
> "new_tag" : "search"
> }
> }
> '
{
"error" : {
"root_cause" : [
{
"type" : "remote_transport_exception",
"reason" : "[node-1][127.0.0.1:9300][indices:data/write/update[s]]"
}
],
"type" : "illegal_argument_exception",
"reason" : "failed to execute script",
"caused_by" : {
"type" : "script_exception",
"reason" : "compile error",
"script_stack" : [
"ctx._source.tags+=new_tag",
" ^---- HERE"
],
"script" : "ctx._source.tags+=new_tag",
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Variable [new_tag] is not defined."
}
}
},
"status" : 400
}

(4) maybe these locations are not writable or multiple nodes were started without increasing

1
2
3
4
5
6
7
8
9
10
11
[2020-01-21T09:45:14,313][ERROR][o.e.b.Bootstrap          ] [elasticsearch_001_data] Exception
java.lang.IllegalStateException: failed to obtain node locks, tried [[/Users/weikeqin1/SoftWare/elasticsearch-6.6.2/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:297) ~[elasticsearch-6.6.2.jar:6.6.2]
...
[2020-01-21T09:45:14,331][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [elasticsearch_001_data] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/Users/weikeqin1/SoftWare/elasticsearch-6.6.2/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-6.6.2.jar:6.6.2]
...
Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[/Users/weikeqin1/SoftWare/elasticsearch-6.6.2/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:297) ~[elasticsearch-6.6.2.jar:6.6.2]
...

(5) Failed to parse value [1] as only [true] or [false] are allowed.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ curl -XPUT 'http://localhost:9200/us/user/1?pretty=1' -d '
> {
> "email" : "john@smith.com",
> "name" : "John Smith",
> "username" : "@john"
> }
> '
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Failed to parse value [1] as only [true] or [false] are allowed."
}
],
"type": "illegal_argument_exception",
"reason": "Failed to parse value [1] as only [true] or [false] are allowed."
},
"status": 400
}

change pretty=1 to pretty=true

failed-to-parse-value-1-as-only-true-or-false-are-allowed

(6) Rejecting mapping update to [gb] as the final mapping would have more than 1 type

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ curl -XPUT 'http://localhost:9200/gb/tweet/3?pretty=true' -H 'Content-Type: application/json' -d '
> {
> "date" : "2014-09-13",
> "name" : "Mary Jones",
> "tweet" : "Elasticsearch means full text search has never been so easy",
> "user_id" : 2
> }
> '
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Rejecting mapping update to [gb] as the final mapping would have more than 1 type: [tweet, user]"
}
],
"type" : "illegal_argument_exception",
"reason" : "Rejecting mapping update to [gb] as the final mapping would have more than 1 type: [tweet, user]"
},
"status" : 400
}

unable-to-create-index-with-more-that-1-type-in-6-x

ElasticSearch 中的索引与类型的前生今世

load_test_data.sh

(7) parsing_exception

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 1,
"col": 86
}
],
"type": "parsing_exception",
"reason": "[terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 1,
"col": 86
},
"status": 400
}

(8) invalid_type_name_exception

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"error": {
"root_cause": [
{
"type": "invalid_type_name_exception",
"reason": "Document mapping type name can't start with '_', found: [_setting]"
}
],
"type": "invalid_type_name_exception",
"reason": "Document mapping type name can't start with '_', found: [_setting]"
},
"status": 400
}

语法错误

References

[1] fielddata
[2] failed-to-parse-value-1-as-only-true-or-false-are-allowed
[3] unable-to-create-index-with-more-that-1-type-in-6-x
[4] ElasticSearch 中的索引与类型的前生今世
[5] load_test_data.sh