ElasticSearch: Java API from 2.x to 5.x issues - elasticsearch

I'm changing from ES 2.x java API to 5.x.
In 2.x I was used to do that in order to create an alias:
AliasAction action = new AliasAction(AliasAction.Type.ADD)
.alias(username)
.index(ElasticsearchRepository.ELASTICSEARCH_INDEX)
.searchRouting(username)
.indexRouting(username)
.filter(QueryBuilders.termQuery("user", username));
request = request.addAliasAction(action);
I0ve tried to figure out how to move that on 5.x. Nevertheless, I don't quite understand how to get that.
Any ideas?

From what I see here : https://www.javadoc.io/doc/org.elasticsearch/elasticsearch/5.0.0
It seems like they changed the way to attribute the alias to something like this :
IndicesAliasesRequest indicesAliasesRequest = new IndicesAliasesRequest();
indicesAliasesRequest.addAliasAction(IndicesAliasesRequest.AliasActions.add()
.alias("TheAliasToAdd")
.index("TheIndexToAddTheAliasTo"));
client.admin().indices().aliases(indicesAliasesRequest);

Related

Alternative to PropertyPathMarker in NEST elasticsearch client library

Im just kick starting my project to migrate elasticsearch from 1.7 to 7.x. As part this, changing my client library NEST to latest version.
Im extensively using PropertyPathMaker class in query generation logic. I can't seem to find what is that I need to use in latest version of NEST.
Can any of you help on this.
Below is the sample code i have problem with.
List<KeyValuePair<PropertyPathMarker, ISort>> BuildSortDetails(Dictionary<string, string> sortDetails,
SortOrder defaultSortOrder,
bool IsCaseInsensitive = false,
Dictionary<string, ListedBoolFilterContainers> nestedFilterDetails = null,
bool preserveSortOrderValue = false);
Field replaces PropertyPathMarker in NEST 2.x onwards.

logstash 5 ruby filter

I've recently upgraded an elk-stack cluster from an old version to 5.1 and although everything looks great, I have an exception occurring frequently in the logstash log, which looks like this:
logstash.filters.ruby Ruby exception occurred: Direct event field references (i.e. event['field']) have been disabled in favor of using event get and set methods (e.g. event.get('field')). Please consult the Logstash 5.0 breaking changes documentation for more details.
The filter I have looks like this:
filter {
ruby {
init => "require 'time'"
code => "event.cancel if event['#timestamp'] < Time.now-(4*86400)"
}
}
Any suggestions ?
The exception contains the answer:
Direct event field references (i.e. event['field']) have been disabled in favor of using event get and set methods (e.g. event.get('field')).
From that, it seems like event.get('#timestamp') is now preferred over event['#timestamp'].

elasticsearch term query with string value containing :(colon)

I am trying to execute a term query with value being a string which has colon in it. It works fine with the sense plugin.
GET XX/XX/_search
{
"query": {
"term" : { "XX.XX" : "7:140453136:T" }
}
}
But the same term query doesnt work with java API.
SearchRequestBuilder response = client.prepareSearch(indexName);
response.setTypes(indexType);
response.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
response.setQuery(QueryBuilders.termQuery("XX.XX", "7:140453136:T"));
response.setFrom(0).setSize(60).setExplain(true);
SearchResponse matchallResponse = response.execute().actionGet()
error:
TransportSerializationException[Failed to deserialize response of type [org.elasticsearch.action.search.SearchResponse]]
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.codecs.lucene50.Lucene50DocValuesFormat
in my mapping i had set this field to be not analyzed. so i am sure elasticsearch is not tokenizing it.
2.I am using ES 2.1.1
I see that there is already a question on this. But the solution posted there dosent solve my problem.
I had the latest lucene core libraries in my classpath which doesnt have Lucene50DocValuesFormat. I replaced the lucene core with 5.3.1 and everything works fine now. Dont use lucene core >5.3.1 with ES 2.1.1 is the solution for this problem. Thanks everyone! Hope this helps!

Does NEST support updating index analysis?

As written in the elasticSearch documentation here, it's possible to define a new analysis for an index (I tried and it worked fine).
I was wondering if it was possible to perform the same thing with NEST?
I tried this:
ElasticClient.CloseIndex("myindex");
IndexSettings ndxSettings = ElasticClient.GetIndexSettings("myindex").Settings;
ndxSettings.Analysis.Analyzers.Add("snbowball", new SnowballAnalyzer());
var r = ElasticClient.UpdateSettings("myindex", ndxSettings);
ElasticClient.OpenIndex("myindex");
No error but nothing has changed.
When I try to see if the analyser has been added:
var getResponse = ElasticClient.GetIndexSettings("myindex");
getResponse.Settings.Analysis.Analyzers contains nothing.
You're doing the right thing, but analysis settings currently aren't on the UpdateWhiteList in NEST:
https://github.com/Mpdreamz/NEST/blob/master/src/Nest/Domain/Settings/IndexSettings.cs

Get "Invalid derived query" error all over the place in our Spring Data JpaRepository interfaces in STS 3.1

We have implemented our repositories exactly as demonstrated in the Spring Data documentation. Everything was fine until we upgraded from STS 2.9 to STS 3.1. All attempts to get these errors to disappear have failed, and in some cases they don't even make sense! They don't match any properties in either the interface or the entities used!
Here is an example:
public interface CreditNotesRepository extends JpaRepository<CreditNotes, Long> {
CreditNotes findCurrentCreditNotes(Long shipmentDetailId);
}
The findCurrentCreditNotes is a named query in our entity. This code executes perfectly fine.
#NamedQueries({
#NamedQuery(name = "CreditNotes.getCount", query = "SELECT COUNT(f) FROM CreditNotes f"),
#NamedQuery(name = "CreditNotes.findCurrentCreditNotes", query =
"SELECT creditNotes FROM CreditNotes creditNotes"
+ " WHERE creditNotes.shipmentDetail.shipmentDetailId = ?1 "
+ " AND creditNotes.notesSeqNumber = (SELECT max(creditNotes2.notesSeqNumber) FROM CreditNotes creditNotes2"
+ " WHERE creditNotes.shipmentDetail.shipmentDetailId = creditNotes2.shipmentDetail.shipmentDetailId)")
})
And the error we get:
Invalid derived query! No property find found for type ca.cole.freight.model.CreditNotes
Although this is just a flag (doesn't affect compilation), it is annoying and confusing. Can anyone shed some light on this? And explain it to me like I'm 6 years old! ;)
At the post on the Spring Forum, Spring Team announced that
It is already fixed for STS 3.3.0
I didn't check this version yet. But I'm using 3.5.0.RELEASE and the problem comes back! My fix is to uncheck Invalid Derived Query
It's an IDE error explained in the following post:
http://forum.springsource.org/showthread.php?138585-Invalid-derived-query!-No-property-delete-found-for-type-java-lang-Object
In the meantime, you can turn off the validation in preferences/spring/project validators/Data validator uncheck invalid derived query and STS wont throw the marker anymore.
There is also workaround for this. Add #Query annotation on your method definition in Your repository without JPQL/SQL query defined.
Here is example :
#Query
List<OwnerModel> findByFirstNameAndAgeNotZero(#Param(value = "firstName") String firstName);
In this case named query OrderModel.findByFirstNameAndAgeNotZero will be used. Your Eclipse error Invalid derived query should also disappear without need of disabling validation as described by #Tuan Dang
Checked on Eclipse 4.5.1 with Spring plugin installed for #NamedQuery and #NamedNativeQuery.
I've just been going through this myself. Unfortunately, the implementation of Spring Data changed between 1.1 and 1.2. It no longer supports the <repository> XML declaration. You can set up a custom postfix, but by default, it expects a bean of class name <InterfaceName>Impl. If it can't find the custom repository implementation, you start getting errors like the one you're encountering. It's trying to create methods to query for objects based on names of methods in your interface.
An alternative is to back your Spring Data version down to 1.1 and specify a schemalocation of http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd in your XML.

Resources