Reading a file in an Elasticsearch plugin

后端 未结 2 655
孤街浪徒
孤街浪徒 2020-12-17 04:14

I am writing an elasticsearch plugin which relies on reading data from a file on disk. When I try to access this file in my code, I get the following exception.



        
相关标签:
2条回答
  • 2020-12-17 04:57

    One way to do this is to start the Elasticsearch process by disabling the security manager, like this:

     bin/elasticsearch -Dsecurity.manager.enabled=false
    

    Since ES 2.x, the Java security manager is enabled by default, it was disabled earlier. Note, though, that this option will be removed in 2.3 because it makes your ES process vulnerable.

    The correct way of doing this is to customize your security policy and specify the file(s) you want to access using policy files:

    grant { 
        permission java.io.FilePermission "/tmp/patient_similarity/codes.txt", "read,write";
    };
    

    You can add this policy in four different locations:

    1. either system wide in $JAVA_HOME/lib/security/java.policy
    2. or for just the elasticsearch user in /home/elasticsearch/.java.policy
    3. or from a file specified on the command line: -Djava.security.policy=someURL
    4. or in the plugin-security.policy file included in your plugin.

    Since you're developing a plugin, you should of course use option 4.

    0 讨论(0)
  • 2020-12-17 05:00

    I had a similar issue in my elasticsearch RestHandler plugin and I was reading the file content from some url say "http://google.com/content.json" I resolved it via below approach -

     `
    String url = "http://google.com/content.json";
    URL fileUrl = new URL(url);
    InputStream is = fileUrl.openStream();
    `
    
    0 讨论(0)
提交回复
热议问题