How is ElasticSearch queried using the Java client? - java

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) ..... );

Related

What is equivalent of cts:element-query in MarkLogic Java API

I have a MarkLogic query written in XQuery and I would like to convert it to Java API using StructuredQueryBuilder. Unfortunately, I can't find Java equivalent for cts:element-query. Can you please show me how to implement it in Java?
The query that I want to convert:
cts:element-query(fn:QName("http://www.example.com/2009/pfi2","content"), cts:word-query("florists", ("case-insensitive","lang=en"), 4.5), ())
The StructuredQueryBuilder.containerQuery() method constructs a search:container-query in the Search API. On the enode, the REST API converts the search:container-query to cts:element-query() or cts:json-property-query() or cts:json-property-scope-query() as appropriate.
For more detail, see:
http://docs.marklogic.com/javadoc/client/com/marklogic/client/query/StructuredQueryBuilder.html#containerQuery-com.marklogic.client.query.StructuredQueryBuilder.ContainerIndex-com.marklogic.client.query.StructuredQueryDefinition-
http://docs.marklogic.com/guide/search-dev/structured-query#id_87231
The other way to provide the query in the Java API is to serialize the cts:element-query() as JSON or XML to learn the query structure and then use a DOM to construct the query and pass the query as a RawCtsQueryDefinition payload.
For that approach, see:
http://docs.marklogic.com/guide/java/searches#id_45762
http://docs.marklogic.com/javadoc/client/com/marklogic/client/query/RawCtsQueryDefinition.html
Hoping that helps,

How to get full explanation of Elasticsearch query Java?

I'm currecntly trying to test out some new score functions on my Elasticsearch query but I'm not yielding the results I am expecting.
I found this on their site about explaining queries here
I can run as a curl command but does anyone know how to translate this to use the Java api?
If you're using the ES5 Java API, you can get the explanation like this:
QueryBuilder query = matchAllQuery(); // your query
ExplainRequest request = new ExplainRequest("index", "type", "id").query(query);
ExplainResponse explainResponse = client.explain(request).actionGet();
Explanation explanation = explainResponse.getExplanation();
Where client is your org.elasticsearch.client.Client instance.

elasticsearch | template query | java API

I was trying to implement the feature of template query. Refer to the last section of http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-template.html
I added a query template using sense. Now the need is through JAVA API of elasticsearch, I need to execute this query template and store the result in SearchResponse. However I am not able to find any API related to query Template. The only class file which is available is TemplateQueryBuilder. This class constructs the template query perfectly but I am not sure of which method to be called from Client in order to pass the object of TemplateQueryBuilder.
Help in this is appreciated.
Here is how to do it :
SearchRequestBuilder request = client;.prepareSearch();
request.setTemplateName(templateName);
request.setTemplateType(ScriptService.ScriptType.INDEXED);
request.setTemplateParams(templateParams);
SearchResponse response = request.get();
You just need to parse the response object then ..
refer to: http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/search.html#java-search-template
Note that with API version 2.X, as request.setTemplateX methods are deprecated, you should use a different approach.
Either you can use request.setTemplate(Template template) which is similar to the accepted answer, or you can go with the more generic QueryBuilders approach:
QueryBuilder qb = QueryBuilders.templateQuery(
"templateName",
ScriptService.ScriptType.FILE,
templateParams);
More to read: https://www.elastic.co/guide/en/elasticsearch/client/java-api/2.4/java-specialized-queries.html#java-query-dsl-template-query

How can I get all database table names in Moodle using API

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'

How to query for user story time in Rally

Using Java, I would like to query Rally for the amount of time that user stories in a specific project took to complete become "Accepted". I have some familiarity with the Rally API already, and have already used it to gather defect data.
Does anyone have any suggestions on how to do this? Thanks!
References:
http://rallytools.github.io/RallyRestToolkitForJava/
https://github.com/RallyTools/RallyRestToolkitForJava/wiki/User-Guide
I also have access to the Rally Web Services API Documentation v2.0 at https://rally1.rallydev.com/slm/doc/webservice/
Instead of looking for "Defects" do a query for "HeirarchicalRequirements"
QueryRequest ustore = new QueryRequest("hierarchicalrequirement");
ustore.setLimit(Integer.MAX_VALUE);
ustore.setFetch(new Fetch("FormattedID","Name","Parent","Feature","Blocked","PlanEstimate","ScheduleState","Release","Iteration","Owner","Project"));
ustore.setQueryFilter(new QueryFilter("Feature.Name","=",feature.getName()));
QueryResponse usResp = restApi.query(ustore);
Search rally tag for Lookback API posts. LBAPI provides historic data.
Even though LBAPI is language agnostic, Rally REST Toolkit for Java does not have a built-in support for it. Currently only javascript AppSDK2 has built-in support for it through snapshotstore.
Unlike Lookback API, WS API gives only the current state of objects. Of course historic data can be gathered from WS API by parsing RevisionHistory,but parsing revisions is expensive and inefficient.
In WS API HierarchicalRequirement has AcceptedDate attribute. This can be accessed directly without having to parse revision history. There is no equivalent for Completed date. You would have to parse revision history to find a revision when a story was set to Completed.

Categories