10

First I wanted to set default analyzer of ES, and failed. And then according to other questions and websites, I'm trying to set default analyzer of one index.But there are some problems too.

I have configured ik analyzer, and I can set some fields' analyzer, here is my command:

curl -XPUT localhost:9200/test

curl -XPUT localhost:9200/test/test/_mapping -d'{
 "test":{
   "properties":{
     "name":{
       "type":"string",
       "analyzer":"ik"
     }
   }
 }
}'

and get the message:

{"acknowledged":true}

also, it works as my wish.

but, if I try to set default analyzer of index:

curl -XPOST localhost:9200/test1?pretty -d '{                                                                           "index":{
"analysis" : {
            "analyzer" : {
                "default" : {
                    "type" : "ik"
                }
            }
        }
    }
}'

I will get error message:

{
  "error" : {
    "root_cause" : [ {
      "type" : "index_creation_exception",
      "reason" : "failed to create index"
    } ],
    "type" : "illegal_argument_exception",
    "reason" : "no default analyzer configured"
  },
  "status" : 400
}

So strange,isn't it? Looking forward to your opinions about this problem. Thanks! :)

iurti
  • 167
  • 2
  • 7

1 Answers1

10

You're almost there, you're simply missing /_settings in your path. Do it like this instead. Also note that you need to close the index first and then reopen it after updating analyzers.

// close index
curl -XPOST 'localhost:9200/test1/_close'

                            add this to the path
                                     |
                                     v
curl -XPUT localhost:9200/test1/_settings?pretty -d '{                                                                           "index":{
"analysis" : {
            "analyzer" : {
                "default" : {
                    "type" : "ik"
                }
            }
        }
    }
}'

// re-open index
curl -XPOST 'localhost:9200/test1/_open'
Val
  • 207,596
  • 13
  • 358
  • 360
  • I input command like yours, then get the error message: { "error" : { "root_cause" : [ { "type" : "invalid_type_name_exception", "reason" : "mapping type name [_settings] can't start with '_'" } ], "type" : "mapper_parsing_exception", "reason" : "mapping [_settings]", "caused_by" : { "type" : "invalid_type_name_exception", "reason" : "mapping type name [_settings] can't start with '_'" } }, "status" : 400 } and maybe you want to me to input: – iurti Jan 20 '16 at 10:19
  • curl -XPOST localhost:9200/test/?pretty -d '{ "settings":{"analysis": { "analyzer" : { "default" : { "type" : "ik" } } } } }}' but – iurti Jan 20 '16 at 10:21
  • Sorry, my bad. you need to close the index first, then the command and then re-open the index. Also you `PUT` and not `POST`. That will work. Also note that the `ik` analyzer must already exist, otherwise it won't work. – Val Jan 20 '16 at 10:23
  • curl -XPOST localhost:9200/test/?pretty -d '{ "settings":{"analysis": { "analyzer" : { "default" : { "type" : "ik" } } } } }}' but get the same error message like the message in my question above. (so sorry i don't know how to use markdown in comment. if i get it, i will edit my comment to be easier to read ) – iurti Jan 20 '16 at 10:28
  • See my answer and copy exactly what you see there. Your comment doesn't take my answer into account. – Val Jan 20 '16 at 10:31
  • eh, in my question i said i succeeded to configure ik for one field in order to tell you that my configuration should be right. And, i just do as your answer, and i find my index will be unavailable after close, setting, open. If only close and open won't be unavailable. Actually, this problem occured before. Do you know why? – iurti Jan 20 '16 at 10:46
  • if you can provide a full re-creation that allows us to reproduce your problem, I'd be glad to try out. – Val Jan 20 '16 at 10:51
  • eh my English is poor, do you mean I describe my command again? create index:`curl -XPUT localhost:9200/test` close index:`curl -XPOST localhost:9200/test/_close` set index: `curl -XPUT localhost:9200/test/_settings?pretty -d '{ "analysis" : { "analyzer" : { "default" : { "type" : "ik" } } } }'` and open index `curl -XPOST localhost:9200/test/_open` – iurti Jan 20 '16 at 11:01
  • then i index some thing: `curl -XPUT localhost:9200/test/test/1 -d '{ "name":"中啊国", "title":"中啊国"}'` and get message : `{ "error" : { "root_cause" : [ { "type" : "unavailable_shards_exception", "reason" : "[test][3] Primary shard is not active or isn't assigned to a known node. Timeout: [1m], request: index {[test][test][1], source[{\n\"name\":\"中啊国\",\n\"title\":\"中啊国\"}]}" } ], "type" : "unavailable_shards_exception", "reason" : "[test][3] Primary shard is not active or isn't ` – iurti Jan 20 '16 at 11:05
  • `"reason" : "[test][3] Primary shard is not active or isn't assigned to a known node. Timeout: [1m], request: index {[test][test][1], source[{\n\"name\":\"中啊国\",\n\"title\":\"中啊国\"}]}" }, "status" : 503 }` – iurti Jan 20 '16 at 11:06
  • I was thinking more like [create a gist](https://gist.github.com/) with all commands you're running so it is easily reproducible for anyone willing to help you. – Val Jan 20 '16 at 11:18
  • Sorry I don't know if you want me to do like this? [link here](https://gist.github.com/zjz12/34d70aacdd04439f4591) – iurti Jan 21 '16 at 03:29
  • The `ik` analyzer is not a built-in one. The question is how do you store it in your index and when? What do you get when retrieving the index settings with `curl -XPUT localhost:9200/test/_settings`? If the `ik` analyzer is not there, that is the problem, because you cannot define a default analyzer based on an unexisting analyzer, that won't work. – Val Jan 21 '16 at 04:41
  • My fault, I didn't make it clear. I get `{"acknowledged":true}` after the index settings with `curl -XPUT localhost:9200/test/_settings`. Also I said I succeeded settings ik analyzer for some certain fields, that could prove my ik analyzer be configured right, couldn't that? – iurti Jan 21 '16 at 07:15
  • If you show the output of `curl -XGET localhost:9200/test/_settings` we'll know for sure which analyzers are in your index settings. – Val Jan 21 '16 at 07:22
  • `'{"test":{"settings":{"index":{"creation_date":"1453384999733","uuid":"h0UBg_IjSGilvWh0HhWMvw","analysis":{"analyzer":{"default":{"type":"ik"}}},"number_of_replicas":"1","number_of_shards":"5","version":{"created":"2000099"}}}}}` 0.o – iurti Jan 21 '16 at 07:28
  • There you go, there's no `ik` analyzer defined, so you cannot set the default one to be `ik`. That's the reason it doesn't work. You need to make sure the `ik` analyzer is defined **before** you use it as default analyzer. – Val Jan 21 '16 at 07:32
  • oh. I just thought I configured ik right. I will try to check my fault. And thanks so much for your helping patiently this days. : ) – iurti Jan 21 '16 at 07:41
  • No problem, don't hesitate to create new questions if you encounter new issues :) – Val Jan 21 '16 at 07:47