elasticsearch-error-notes

(1) index_not_found_exception

{
    "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

$ 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
简单来说就是修改如下配置

$ 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

$ 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

[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.

$ 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

$ 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

{
    "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

{
    "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
}

语法错误

(9) [ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse field [stdSpecialAttrMap] of type [text]]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_state_exception, reason=Can’t get text on a START_OBJECT at 1:1831]];]

[ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=failed to parse field [stdSpecialAttrMap] of type [text]]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_state_exception, reason=Can't get text on a START_OBJECT at 1:1831]];]

Could not index event to Elasticsearch

动态索引没有显示指定字段,es不知道如何处理
stdSpecialAttrMap.attr_*

(10) The difference between max_gram and min_gram in NGram Tokenizer must be less than or equal to: [1] but was [49]. This limit can be set by changing the [index.max_ngram_diff] index level setting.

{
    "reason":"The difference between max_gram and min_gram in NGram Tokenizer must be less than or equal to: [1] but was [49]. This limit can be set by changing the [index.max_ngram_diff] index level setting.",
    "type":"illegal_argument_exception",
    "root_cause":[
        {
            "reason":"The difference between max_gram and min_gram in NGram Tokenizer must be less than or equal to: [1] but was [49]. This limit can be set by changing the [index.max_ngram_diff] index level setting.",
            "type":"illegal_argument_exception"
        }
    ]
}

从es 6 到 es7 配置变了,需要加个 "max_ngram_diff": "50" 的配置

trying-to-set-the-max-gram-and-min-gram-in-elasticsearch

11 Root mapping definition has unsupported parameters: [docs : {properties={username={type=keyword}, address={type=keyword, fields={search={analyzer=ngram_min1_max50, type=text}}}}}]

{
    "reason": "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [docs : {properties={username={type=keyword}, address={type=keyword, fields={search={analyzer=ngram_min1_max50, type=text}}}}}]",
    "caused_by": {
        "reason": "Root mapping definition has unsupported parameters: [docs : {properties={username={type=keyword}, address={type=keyword, fields={search={analyzer=ngram_min1_max50, type=text}}}}}]",
        "type": "mapper_parsing_exception"
    },
    "type": "mapper_parsing_exception",
    "root_cause": [
        {
            "reason": "Root mapping definition has unsupported parameters: [docs : {properties={username={type=keyword}, address={type=keyword, fields={search={analyzer=ngram_min1_max50, type=text}}}}}]",
            "type": "mapper_parsing_exception"
        }
    ]
}

es7 mapping 里不需要设置type

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
[6] trying-to-set-the-max-gram-and-min-gram-in-elasticsearch