ElasticsearchRepository dynamic indexName - java

In my project I am using ElasticsearchRepository, when my class is extending the ElasticsearchRepository.
Is there a way to change indexName property dynamically, I don't want to use #Document, since my indexName is dynamic?

The #Document(indexName = "xxx") can be a SpEL expression. The expression is parsed whenever the index name is needed by SDE to obtain the index name. So, you could make the name be based on something you configure at runtime, via the application.yml file for example. In theory, anything you can do in SpEL should be possible.
I'm using it to define a "prefix" value that is prependded to all the index names to allow me to run multiple applications with the same base index names in the same ES cluster without clashing with each other. So I have my #Document() tag as:
#Document(indexName = "#{environment.getRequiredProperty('es.prefix') + '-doc'}")
And then I configure the es.prefix to be the value I want in the application.properties or application.yml file.

Related

JsonAlias as default openapi dto property name

I have a dto used as request body in a rest service:
#Data
public class MyClass {
#JsonAlias("myAlias")
private String myProperty;
}
When we produce our openapi/swagger yaml the property name is "myProperty"
Is it possible to automatically force the alias inside the openapi/swagger produced?
(annotation? during yaml creation? anything else?)
Serialization always uses the primary name - in this case, myProperty. In order to change the outputted name, you'd need to change the name of myProperty. The JsonAlias annotation only affects deserialization - the alias is an alternate name.

Java: How to provide value to annotation attribute fetched from a properties file?

It always say that The value for annotation attribute WebServiceClient.wsdlLocation must be a constant expression.
But i need to load value from properties file as on QA/Prod/SIT, the URL is different.
How can i manage same in annotation?

Is it possible to retrieve the entire list of named AnnotationSets in GATE?

is it possible to retrieve the entire list of an Annotation Set in GATE? This line of code returns all the items of a GATE document that belong to the AnnotationSet called "EMail";
AnnotationSet annSet = doc.getAnnotations().get("EMail");
Now, how can I know all of the Annotations' Set names instead of the only "EMail"?
Isn't this the answer to your question:
AnnotationSet annSet = doc.getAnnotations();
I think you mix two different terms: annotation set and annotation type. Be careful about these two...
There are several methods of gate.Document and gate.AnnotationSet that can be used:
gate.Document.getAnnotations() ... all annotations from the default (without name) annotation set.
gate.Document.getAnnotations(String setName)... all annotations from named annotation set with name setName.
gate.AnnotationSet.get(String anntoationType)... select only annotations with given anntoationType.
gate.Document.getAnnotationSetNames()... get all the names of named annotation sets in a document
gate.AnnotationSet.getAllTypes()... get set of all annotation type names of annotations present in given annotation set.
See more details in javadoc:
SimpleAnnotationSet
SimpleDocument
Document doc;
// create/manipulate the document...
Set<String> names = doc.getAnnotationSetNames();
Map<String, AnnotationSet> namedAnnSets = doc.getNamedAnnotationSets();
// The default AS always exists
AnnotationSet defaultAS = doc.getAnnotations();
Note that a GATE document always has a default (unnamed) annotation set, which is not included in the set of names or map of named sets.

Spring Data Elasticsearch - Create keyword field with normalizer

We are using the spring-data-elasticsearch project to interface with our elasticsearch clusters, and have been using it now for around a year. Recently, we moved to elasticsearch 5.x (from 2.x) where we now have the "keyword" datatype.
I would like to index these keywords as lowercase values, which I know can be done with field normalizers. I can't find anywhere in the documentation or online where I can add a normalizer to a field through the annotation based mapping.
E.g
#Field(type = FieldType.keyword, <some_other_param = some_normalizer>)
Is this something that can be done? I know that we can use JSON based mapping definitions as well, so I will fall back to that option if needed, but would like to be able to do it this way if possible.
Any help would be very appreciated!
Since the pull request of #xhaggi has been merged (spring-data-elasticsearch 3.1.3+ or Spring Boot 2.1.1), we have a normalizer field in the #Field annotation.
To use it, we need:
declare a #Field or an #InnerField with params type = FieldType.Keyword, normalizer = "%NORMALIZER_NAME%"
add #Setting(settingPath = "%PATH_TO_NORMALIZER_JSON_FILE%") at the class level.
put the normalizer mapping into a json file at %PATH_TO_NORMALIZER_JSON_FILE%
Example of usage
FYI, for anyone looking at this, the answer is there is not a way to do this at this time.
You can do this, however, by creating your mappings file as JSON in the Elasticsearch format. See:
https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
You can then create that JSON file and link it to your Domain model with.
#Mapping(mappingPath = "some/path/mapping.json")
Note that this is not, in my experience, compatible with the provided annotation based mapping for fields.
There is a pending issue https://jira.spring.io/browse/DATAES-492 waiting for review.

Path based on a non-PK unique field in spring-data-rest

Given an #Entity declared with the following fields:
#Id
private String idgeo;
private String isoCtryCd;
private String randomField;
with the default spring configuration I get resource paths ending with .../{idgeo}.
Is there an option in the spring configuration to use other (unique) fields as the resource path ending? In my example it'd be .../{isoCtryCd}
Thank you!
Actually this feature will be introduced in Spring Data Rest 2.5. Currently there is a 2.5.0.M1 milestone release containing this feature.
This part of the documentation shows how to use a different entity attribute for item resource uris.
http://docs.spring.io/spring-data/rest/docs/2.5.0.M1/reference/html/#_customizing_item_resource_uris

Categories