0

I have a model which is:

@Document(indexName = "index", type = "logs")
public class Log {

    @Id
    private String id;

    private String test_no;
    private String entire_log;
    private String method;
    private String timestamp;
    private String thread_name;
    private String level;
    private String logger_name;
    private String formatted_message;

    // CONSTRUCTORS, GETTERS AND SETTERS...
}

I have an applicationContext.xml file which contains a bean, used to save the value of the dynamic index. The location of this file is inside of src/main/resources directory, the same location than application.properties file. The bean is:

<bean id="index" class="elastest.loganalyzer.es.client.model.Index">
    <property name="v" value="defaut"></property>
</bean>

where the Index class is a simple class which contains a param "v":

public class Index {

    String v;

    public Index() {
        this.v = "default";
    }

    public String getV() {
        return v;
    }

    public void setV(String v) {
        this.v = v;
    }

}

What I want to do is to make the index of the above model (Log) dynamic. I have tried it by different ways but I can't find the correct solution:

@Document(indexName = "#{index}", type = "logs")
@Document(indexName = "#{index.v}", type = "logs")
@Document(indexName = "#{index.getV()}", type = "logs")

So... How can I make it works?

7
  • Have you tried this ? "#{'${index.v}'}" Commented Feb 2, 2018 at 9:43
  • @Val I did, and elasticsearch creates an index called ${index.v}, and It doesn't contain the value that I give it. Commented Feb 2, 2018 at 12:04
  • @CarlosVázquezLosada any luck with this. I am on the same boat as you here. In my particular case I am trying to dynamically apply the index name from a field in the documents(pojo bean) that is tagged with the @Document Commented Feb 23, 2018 at 10:34
  • I didn't resolve the problem. I abandoned the spring methods and came back to the old method.... Commented Apr 5, 2018 at 15:39
  • Which is the old method, @Grancein ? I didn't resolve this problem yet... Commented Apr 6, 2018 at 10:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.