Use Elasticsearch FIlter JSON directly in JAVA Api

Hi All,

I am passing the JSON String to wrapperFilter method.

FilterBuilder filterBuilder = FilterBuilders.wrapperFilter("{"filter":
{"and"=[{"term":{"c24":TEXT} }, {"term":{"C25":text} }]} }");

FilteredQueryBuilder qb = QueryBuilders.filteredQuery(queryBuilder,
filterBuilder);

System.out.println("Query : " + qb);

SearchResponse searchResponse = null;
// SortBuilder sort=SortBuilders.fieldSort("c0").order(SortOrder.DESC);
searchResponse = client.prepareSearch("ipdr").addField("c0")
.setQuery(qb).setSize(10000)
.setSearchType(SearchType.QUERY_THEN_FETCH).execute()
.actionGet();
for (SearchHit hit : searchResponse.getHits()) {

try {
System.out.println(hit.getFields().get("c0").getValue()
.toString());
} catch (Exception e) {
e.printStackTrace();
}
}

But, ES will internally fire following query to fetch records:

{
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"wrapper" : {
"filter" :
"eyJmaWx0ZXIiOiB7ImFuZCI9W3sidGVybSI6eyJjMjQiOlRFWFR9IH0sIHsidGVybSI6eyJDMjUiOnRleHR9IH1dfSB9"
}
}
}
}

Can you guide me to sort out the issue.

Thanks,
Ankit Jain

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

I find it's much better and easier to create searches in Java (you're doing
that) and then use Java all the way and not try to create JSON (the hard
way) or try to create Java-escaped JSON string (the really really hard way).

Start with the JavaDoc at http://es-java-doc.medcl.net/

Look at the static methods of the QueryBuilders and FilterBuilders classes.
They'll create your query and filter terms as needed. This is much easier.

The create an option in your application to call the root query's (or
filter's) toString method to create the JSON string for posting to this
newsgroup.

But do the work in Java all the way, and you'll find it much easier.

Hope this helps!

On Tuesday, May 7, 2013 10:52:03 AM UTC-4, Ankit Jain wrote:

Hi All,

I am passing the JSON String to wrapperFilter method.

FilterBuilder filterBuilder = FilterBuilders.wrapperFilter("{"filter":
{"and"=[{"term":{"c24":TEXT} }, {"term":{"C25":text} }]} }");

FilteredQueryBuilder qb = QueryBuilders.filteredQuery(queryBuilder,
filterBuilder);

System.out.println("Query : " + qb);

SearchResponse searchResponse = null;
// SortBuilder sort=SortBuilders.fieldSort("c0").order(SortOrder.DESC);
searchResponse = client.prepareSearch("ipdr").addField("c0")
.setQuery(qb).setSize(10000)
.setSearchType(SearchType.QUERY_THEN_FETCH).execute()
.actionGet();
for (SearchHit hit : searchResponse.getHits()) {

try {
System.out.println(hit.getFields().get("c0").getValue()
.toString());
} catch (Exception e) {
e.printStackTrace();
}
}

But, ES will internally fire following query to fetch records:

{
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"wrapper" : {
"filter" :
"eyJmaWx0ZXIiOiB7ImFuZCI9W3sidGVybSI6eyJjMjQiOlRFWFR9IH0sIHsidGVybSI6eyJDMjUiOnRleHR9IH1dfSB9"
}
}
}
}

Can you guide me to sort out the issue.

Thanks,
Ankit Jain

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Have also a look at Elasticsearch Platform — Find real-time answers at scale | Elastic

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 7 mai 2013 à 23:51, InquiringMind brian.from.fl@gmail.com a écrit :

I find it's much better and easier to create searches in Java (you're doing that) and then use Java all the way and not try to create JSON (the hard way) or try to create Java-escaped JSON string (the really really hard way).

Start with the JavaDoc at http://es-java-doc.medcl.net/

Look at the static methods of the QueryBuilders and FilterBuilders classes. They'll create your query and filter terms as needed. This is much easier.

The create an option in your application to call the root query's (or filter's) toString method to create the JSON string for posting to this newsgroup.

But do the work in Java all the way, and you'll find it much easier.

Hope this helps!

On Tuesday, May 7, 2013 10:52:03 AM UTC-4, Ankit Jain wrote:

Hi All,

I am passing the JSON String to wrapperFilter method.

FilterBuilder filterBuilder = FilterBuilders.wrapperFilter("{"filter": {"and"=[{"term":{"c24":TEXT} }, {"term":{"C25":text} }]} }");

  FilteredQueryBuilder qb = QueryBuilders.filteredQuery(queryBuilder, filterBuilder);

  
  System.out.println("Query   :  " + qb);

  SearchResponse searchResponse = null;
  // SortBuilder sort=SortBuilders.fieldSort("c0").order(SortOrder.DESC);
  searchResponse = client.prepareSearch("ipdr").addField("c0")
  		.setQuery(qb).setSize(10000)
  		.setSearchType(SearchType.QUERY_THEN_FETCH).execute()
  		.actionGet();
  for (SearchHit hit : searchResponse.getHits()) {

  	try {
  		System.out.println(hit.getFields().get("c0").getValue()
  				.toString());
  	} catch (Exception e) {
  		e.printStackTrace();
  	}
  }

But, ES will internally fire following query to fetch records:

{
"filtered" : {
"query" : {
"match_all" : { }
},
"filter" : {
"wrapper" : {
"filter" : "eyJmaWx0ZXIiOiB7ImFuZCI9W3sidGVybSI6eyJjMjQiOlRFWFR9IH0sIHsidGVybSI6eyJDMjUiOnRleHR9IH1dfSB9"
}
}
}
}

Can you guide me to sort out the issue.

Thanks,
Ankit Jain

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.