I am new to ElasticSearch. I want to convert below query:
GET /snomed_v1/_analyze?analyzer=english
{ 12 O'clock, superior margin }
to the Java api query.
Thanks.
Connect to your ES cluster as per the basics here: https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html
Your query will ask the admin interface for an AnalyzeRequest(index, query) with the english analyzer:
ESClient.admin().indices().analyze(new AnalyzeRequest("snomed_v1", "12 O'clock, superior margin").analyzer("english"));
Related
This question already has answers here:
MongoDB GUI client (cross-platform or Linux) [closed]
(5 answers)
Closed 3 years ago.
I need to perform the following MongoDB query in Java:
db.ventas.aggregate([
{
$sort: {"codArt._id": -1}
},
{
$group:{
_id: "$codArt._id",
denominacion: {"$first": "$codArt.denominacion"},
unidades: {"$sum": "$unidades"},
importe: {"$first": {"$multiply": [{"$sum": "$unidades"}, "$codArt.pvp"]}},
stock: {"$first": {"$subtract": ["$codArt.stock", "$unidades"]}}
}
}
])
Is there any library, which can do it?
Unfortunately, I can't install MongoDB Compass.
You could use something like Hibernate, but no automatic translation is provided... you'll need to build your model. It will be useful though if you do not want to build the inner query or need some portability.
http://hibernate.org/ogm/
There is a great tool to learn MongoDB Java Syntax and to work with MongoDB in general: Studio 3T, there you can generate a MongoDB query for the Java driver. Trial 30 days.
P.S. I'm not sure if this software requires admin rights to be installed.
I'm still new with No SQL solution and I just starting to learn nosql since few months ago.
I have a project and it was built by spring boot framework and has a DAO layer. My database was cassandra and I'm using datastax java cassandra driver to communicate. I found cassandra or maybe all nosql key/value solutions don't support for case sensitive and query with "like%" use cases. After done some research through stackoverflow and other forums, figure out those have to use some tools like apache spark, elastic search, or apache lucene to dig the data in cassandra. So that I chose apache spark and i'm not sure whether the code should be done in this way (in term of best practice).
Here's my code to query data:
#Override
public Login getLoginByEmail(String shopId, String email) throws InterruptedException, ExecutionException {
JavaFutureAction<List<Login>> loginRDDFuture = javaFunctions(getSparkContext())
.cassandraTable("shop_abc", "app_login", loginRowReader)
.filter(new Function<Login, Boolean>() {
private static final long serialVersionUID = 1L;
#Override
public Boolean call(Login login) throws Exception {
return login.getEmail().equalsIgnoreCase(email.trim());
}
}).collectAsync();
List<Login> lgnList = loginRDDFuture.get();
if(lgnList.size() > 0){
return lgnList.get(0);
}
return null;
}
It took me 9 seconds to get the result and database only with a table and 3 records. I would think that what happen if the database if more than million records.
I'm not sure whether this is good practice or it has better way or better tools to do that, I hope someone can give me a guidance.
Appreciate.
I think this kind of query will be rather slow because it has to retrieve all data from your C* database, breaking up queries by token ranges and mapping them into RDDs and then filters through them using a spark job. That is going to have some overhead even when your data set is small, although 9 seconds does seem like quite a while, but hard to know why without knowing more about your environment.
Alternatively, have you considered using SSTable Attached Secondary Indices (SASI)? SASI was introduced in C* 3.4 and allow you to do LIKE % queries with cassandra with or without case sensitivity, i.e.:
CREATE CUSTOM INDEX fn_suffix_allcase ON cyclist_name (firstname)
USING 'org.apache.cassandra.index.sasi.SASIIndex'
WITH OPTIONS = {
'mode': 'CONTAINS',
'analyzer_class':'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer',
'case_sensitive': 'false'
};
A good talk for reference on SASI is SASI: Cassandra on the Full Text Search Ride.
I need list of the database tables used by Moodle.
How can I get it ? Is there any API for that either in Java or PHP ?
I checked - APIs like - Data definition API, Data Manipulation API , Web Services but I could not find what I require.
These API help getting data from Moodle, but I need MetaData.
Please help. Thanks in Advance.
You can use this in Moodle
$tables = $DB->get_tables();
also
foreach ($tables as $table) {
$columns = $DB->get_columns();
foreach ($columns as $column) {
...
}
}
Or use the information_schema
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'yourmoodledatabasename'
I am working in a Spring web application using Cassandra with Astyanax client. I want to transform result data retrieved from Cassandra queries to a POJO, but I do not know which library or Astyanax API support this.
For example, I have User column family (CF) with some basic properties (username, password, email) and other related additional information can be added to this CF. Then I fetch one User row from that CF by using OperationResult> to hold the data returned, like this:
OperationResult<ColumnList<String>> columns = getKeyspace().prepareQuery(getColumnFamily()).getRow(rowKey).execute();
What I want to do next is populating "columns" to my User object. Here, I have 2 problems and could you please help me solve this:
1/ What is the best structure of User class to hold the corresponding data retrieved from User CF? My suggestion is:
public class User {
String userName, password, email; // Basic properties
Map<String, Object> additionalInfo;
}
2/ How can I transform the Cassandra data to this POJO by using a generic method (so that it can be applied to every single CF which has mapped POJO)?
I am so sorry if there are some stupid dummy things in my questions, because I have just approached NoSQL concepts and Cassandra as well as Astyanax for 2 weeks.
Thank you so much for your help.
You can try Achilles : https://github.com/doanduyhai/achilles, an JPA compliant Entity Manager for Cassandra
Right now there is a complete implementation using Thrift API via Hector.
The CQL3 implementation using Datastax Java Driver is in progress. A beta version will be available in few months (July-August 2013)
CQL3 is great but it's still too low level because you need to extract the data yourself from the ResultSet. It's like coming back to the time when only JDBC Template was available.
Achilles is there to fill the gap.
I would suggest you to use some library like Playorm using which you can easily perform CRUD operations on your entities. See this for an example that how you can create a User object and then you can get the POJO easily by
User user1 = mgr.find(User.class, email);
Assuming that email is your NoSqlId(Primary key or row key in Cassandra).
I use com.netflix.astyanax.mapping.Mapping and com.netflix.astyanax.mapping.MappingCache for exactly this purpose.
The site only has documentation for JSON, but not the Java client. Is there some sort of mapping I should be performing?
For example geo location queries:
http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-range-filter.html
How would such a query be written using the Java client?
Thanks
Jason
Not obvious but not that complicated ;)
SearchRequestBuilder srb = client.prepareSearch(index);
srb.setQuery(QueryBuilders.matchAllQuery());
srb.setFilter(FilterBuilders.geoDistanceRangeFilter("filter1").lat(1234).lon(4321).geoDistance(GeoDistance.PLANE) ..... );