Category Archives: Programming

Elasticsearch – Date/Time(String) Add/Subtract Duration – Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch - DateTime(String) Add/Subtract Duration - Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch – Date/Time(String) Add/Subtract Duration – Days,Months,Years,Hours,Minutes,Seconds

Elasticsearch - DateTime(String) Add/Subtract Duration - Days,Months,Years,Hours,Minutes,Seconds

Sample Query : POST /test/test/_search { “query”: { “filtered”: { “filter”: { “bool”: { “must”: [{ “range”: { “dateOrTimeAttribute”: { “from”: “16:31:15”, “to”: “16:31:15||+10m” } } }] } } } } } Examples: “16:31:15||+10m” “16:31:15||+1d” “2016-02-02||-1M”  

Java – Read/Parse Command Line Arguments/Options

Java - Read/Parse Command Line Arguments/Options

Java – Read/Parse Command Line Arguments/Options

Java - Read/Parse Command Line Arguments/Options

Maven Dependency : <dependency> <groupId>commons-cli</groupId> <artifactId>commons-cli</artifactId> <version>1.2</version> </dependency> Sample Java Program : package test; import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; public class Test { public static void main(String[] args) { //Define Options Options options = new Options(); //Option Name – option1 //Has input value – true options.addOption(“option1”, true, “Option 1 Description”);… Read More »

Java JConsole – Local Process List Empty – Solved

JAVA JCONSOLE – LOCAL PROCESS LIST EMPTY – SOLVED.png

Java JConsole – Local Process List Empty – Solved

JAVA JCONSOLE – LOCAL PROCESS LIST EMPTY – SOLVED.png

JConsole or  Java Monitoring and Management Console Open command prompt Execute the command echo %TMP% Now you will get a path to a folder where temporary files are stored. E.g. C:\Users\Username\AppData\Local\Temp Go to that folder Remove the folder named hsperfdata_USERNAME Restart JConsole application and now you will have the list of currently running Java processes in the local process… Read More »

Elasticsearch – Compare/ScriptFilter/Condition on Two Fields using Script Filter – REST Query + Java API

Elasticsearch - Compare or Script Filter or Condition on Two Fields using Script Filter - REST Query + Java API

Elasticsearch – Compare/ScriptFilter/Condition on Two Fields using Script Filter – REST Query + Java API

Elasticsearch - Compare or Script Filter or Condition on Two Fields using Script Filter - REST Query + Java API

Example 1: GET /INDEX/TYPE/_search { “query”: { “filtered”: { “filter”: { “script”: { “script”: “doc[‘field1’].value < doc[‘field2’].value” } } } } } Example 2: GET /INDEX/TYPE/_search { “query”: { “filtered”: { “filter”: { “script”: { “script”: “doc[‘field1’].value – doc[‘field2’].value > 10” } } } } } Java API: import org.elasticsearch.index.query.FilterBuilders; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import… Read More »

Elasticsearch – Use Script Filter/Conditon in Aggregation/Sub-Aggreagtion

Elasticsearch - Use Script Filter or Conditon in Aggregation or Sub-Aggreagtion

Elasticsearch – Use Script Filter/Conditon in Aggregation/Sub-Aggreagtion

Elasticsearch - Use Script Filter or Conditon in Aggregation or Sub-Aggreagtion

Example 1 – REST: GET /INDEX/TYPE/_search { “size”: 0, “aggs”: { “FILTER_NAME”: { “filter”: { “script”: { “script”: “doc[‘field1’].value < doc[‘field2’].value” } } } } } Example 1 – Java API: SearchRequestBuilder searchRequestBuilder = esClient .prepareSearch(“INDEX) .setTypes(“TYPE”) .setSize(0) .addAggregation( AggregationBuilders.filter(“FILTER_NAME”).filter(FilterBuilders.scriptFilter(“doc[‘filed1’].value > doc[‘field2’].value”))); SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); Map<String, Aggregation> aggMap = searchResponse.getAggregations().asMap(); InternalFilter filter = (InternalFilter)… Read More »