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!
Related
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.
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);
I'm using spring-data-mongodb 1.8.0; MongoDB 3.0.6; mongo-java-driver 3.1.0;spring-framework.version 4.0.3.
What I want is to query a list of user with certain phone numbers.
example for user: { "_id" : ObjectId("5625e5c32e1ca013a03f0d1b"), "phone" : "12345535"}
In Mongo Shell db.user.find({phone: { $in: [ "12345535", "123535"]}}) works fine. But in Spring I failed. Java Class User(with getters/setters omitted):
#Document(collection = "user")
public class User {
#Id
String id;
String phone;
}
What I tried is:
Query q = new Query(Criteria.where("phone").in("12345535","123535"));
mongoTemplate.find(q, User.class);
It comes to error:
Exception in thread "main" java.lang.IllegalAccessError: tried to access class org.springframework.beans.PropertyMatches from class org.springframework.data.mapping.PropertyReferenceException
at org.springframework.data.mapping.PropertyReferenceException.detectPotentialMatches(PropertyReferenceException.java:134)
at org.springframework.data.mapping.PropertyReferenceException.<init>(PropertyReferenceException.java:59)
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:75)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:327)
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)
at org.springframework.data.mongodb.core.convert.QueryMapper$MetadataBackedField.getPath(QueryMapper.java:837)
at org.springframework.data.mongodb.core.convert.QueryMapper$MetadataBackedField.<init>(QueryMapper.java:729)
at org.springframework.data.mongodb.core.convert.QueryMapper$MetadataBackedField.with(QueryMapper.java:740)
at org.springframework.data.mongodb.core.convert.QueryMapper$MetadataBackedField.with(QueryMapper.java:686)
at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:258)
at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObjectForField(QueryMapper.java:200)
at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:123)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1700)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1690)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:602)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:593)
at com.example.TestMongo.main(TestMongo.java:30)
But with changing field phone to id, same code works fine.
Query q = new Query(Criteria.where("id").in("5625e5c32e1ca013a03f0d1b","f0d1e"));
mongoTemplate.find(q, User.class);
With debugging, I find that it even didn't go to the request phase, error occurred in the query-building phase. It seems $in cannot be processed by PropertyPath.create, while in the id case, it can.
How can I fix this? I am a newbie and searched a lot but got no luck.Can you please help me out. Every answer is appreciated. Thanks guys.
As indicated in the announcement blog and the release train wiki, Spring Data MongoDB 1.8 requires Spring 4.1, ideally 4.1.8 which includes an important security fix.
The issue have appeared on me while using Spring 4.2.3.RELEASE and Spring MongoDB 1.6.1
Switching to Spring mongoDB 1.8.1 solves the issue.
(Meant as a comment to #OliverGierke's answer, but couldn't do it, due to low reputation level.)
I'm trying to calculate the tf*idf of a term in my index.
Following Yonik's post from http://yonik.com/posts/solr-relevancy-function-queries/ I tried
http://localhost:8080/solr/select/?fl=score,id&defType=func&q=mul(tf(texto_completo,bug),idf(texto,bug))
(where texto_completo is the field, and 'bug' is the term) without much success. The response was:
error 400: The request sent by the client was syntactically incorrect (null).
I went ahead and looked at this answer /a/13477887 so I tried to do a simpler function query:
http://localhost:8080/solr/select/?q={!func}docFreq(texto_completo,bug)
And yet, I got the same error.
What is my syntax lacking to work properly?
For this not working:
q={!func}docFreq(texto_completo,bug)
use all lower-case docfreq:
q={!func}docfreq(texto_completo,bug)
I just tried:
q={!func}mul(tf(name,movie),idf(name,movie))
in Solr 4.2.1 and it is working fine. My field name is name (Text type) and term I am looking for is movie.
UPDATE: You need at least Solr 4.0 to use these. See http://wiki.apache.org/solr/FunctionQuery#Relevance_Functions
I'm using tire and elasticsearch. The service has started using port 9200. However, it was returning 2 errors:
"org.elasticsearch.search.SearchParseException: [countries][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query":{"query_string":{"query":"name:"}}}]]"
and
"Caused by: org.apache.lucene.queryParser.ParseException: Cannot parse 'name:': Encountered "<EOF>" at line 1, column 5."
So, I reinstalled elasticsearch and the service container. Service starts fine.
Now, when I search using tire I get no results when results should appear and I don't receive any error messages.
Does anybody have any idea how I might find out what is wrong, let alone fix it?
first of all, you don't need to reindex anything, in the usual cases. It depends how you installed and configured elasticsearch, but when you install and upgrade eg. with Homebrew, the data are persisted safely.
Second, no need to reinstall anything. The error you're seeing means just what it says on the tin: SearchParseException, ie. your query is invalid:
{"query":{"query_string":{"query":"name:"}}}
Notice that you didn't pass any query string for the name qualifier. You have to pass something, eg:
{"query":{"query_string":{"query":"name:foo"}}}
or, in Ruby terms:
Tire.index('test') { query { string "name:hey" } }
See this update to the Railscasts episode on Tire for an example how to catch errors due to incorrect Lucene queries.