Failed to start elasticsearch when enable CORS


(Weizhen Yan) #1

Tried to enable HTTP CORS on ES, but after I added
http.cors.enabled: true
http.cors.allow-origin: "*"
to elasticsearch.yml, ES can't start and I got this error:

Exception in thread "main" SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: ParserException[while parsing a block mapping
 in 'reader', line 17, column 1:
    cluster.name: elasticsearch_roccia
    ^
expected <block end>, but found BlockMappingStart
 in 'reader', line 59, column 3:
      http.cors.enabled: true
      ^
];
Likely root cause: while parsing a block mapping
 in 'reader', line 17, column 1:
    cluster.name: elasticsearch_roccia
    ^
expected <block end>, but found BlockMappingStart
 in 'reader', line 59, column 3:
      http.cors.enabled: true
  ^
at com.fasterxml.jackson.dataformat.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingKey.produce(ParserImpl.java:570)
at com.fasterxml.jackson.dataformat.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
at com.fasterxml.jackson.dataformat.yaml.snakeyaml.parser.ParserImpl.getEvent(ParserImpl.java:168)
at com.fasterxml.jackson.dataformat.yaml.YAMLParser.nextToken(YAMLParser.java:342)
at org.elasticsearch.common.xcontent.json.JsonXContentParser.nextToken(JsonXContentParser.java:53)
at org.elasticsearch.common.settings.loader.XContentSettingsLoader.serializeObject(XContentSettingsLoader.java:99)
at org.elasticsearch.common.settings.loader.XContentSettingsLoader.load(XContentSettingsLoader.java:67)
at org.elasticsearch.common.settings.loader.XContentSettingsLoader.load(XContentSettingsLoader.java:45)
at org.elasticsearch.common.settings.loader.YamlSettingsLoader.load(YamlSettingsLoader.java:46)
at org.elasticsearch.common.settings.Settings$Builder.loadFromStream(Settings.java:1074)
at org.elasticsearch.common.settings.Settings$Builder.loadFromPath(Settings.java:1061)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareEnvironment(InternalSettingsPreparer.java:88)
at org.elasticsearch.common.cli.CliTool.<init>(CliTool.java:107)
at org.elasticsearch.common.cli.CliTool.<init>(CliTool.java:100)
at org.elasticsearch.bootstrap.BootstrapCLIParser.<init>(BootstrapCLIParser.java:48)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:241)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)

Refer to the log for complete error details.

Need some help ! Thank you


(Magnus Bäck) #2

Looks like your configuration file isn't valid YAML. Pay attention to the indentation. If you post the configuration file here we can help you debug it, but make sure you format it as code using the toolbar button.


(Weizhen Yan) #4

Thank you !
http://pastie.org/10677234
here is my elasticsearch.yml, always can't make code style show correctly in the post... sry for any inconvenience .


(Magnus Bäck) #5

Here's the problem:

...
# Set a custom port for HTTP:
#
# http.port: 9200
  http.cors.enabled: true
  http.cors.allow-origin: "*"
#
...

Don't indent the http.cors.* lines.


(Weizhen Yan) #6

what do u mean by dont indent? like this?

...
# Set a custom port for HTTP:
#
# http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
#
...

(Weizhen Yan) #7

fix it!! thank you! I should read some yml doc - -!


(Magnus Bäck) #8

Yes, exactly. No whitespace at the beginning of the line.


(system) #9