FacetFilter for DateHistogramFacet

Hi All,
I am facing two problems in my code:
1.
I am using date histogram facet for implementing time chart. While
applying multi-filter for the facet I am facing error like Failed to
execute.
My Code is working when I am using
searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("1").facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(queryFilter(termQuery("mediatypeid","1"))));

But if I place this code inside a for loop for changing mediatypeid
value like
String mediatypeArray[i]={1,2,3,4};
for(int i=0; i<mediatypeArray[i];i++)
{
searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("daterange"+mediatypeArray[i]).facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(queryFilter(termQuery("mediatypeid",mediatypeArray[i]))));
}

The above mediatypeArray contains a set of mediatype ids

And also I cant able to apply filter for this facet.

  1. I need a time line graph for number of posts for particular date
    I need a facet like

"date e.g(1328054400000)" : {
"_type" : "date_histogram",
"entries" : [ {
"term" : 1,
"count" : 4
}]
}

but I am getting like this,
"print" : {
"_type" : "date_histogram",
"entries" : [ {
"time" : 1328054400000,
"count" : 4
}, {
"time" : 1328140800000,
"count" : 1
}, {
"time" : 1328227200000,
"count" : 1
}, {
"time" : 1328400000000,
"count" : 1
}, {
"time" : 1328486400000,
"count" : 4
}, {
"time" : 1328572800000,
"count" : 3
}, {
"time" : 1328659200000,
"count" : 1
} ]
}

Could you please help in this?.Hope I will resolve my problem soon.
Thanks in advance,

Thanuja

What is the failure that you are getting?

Also, in your code, you set the facet filter twice on the same date histogram, why? Note, make sure to use relevant filter, and not a query filter wrapping a query (i.e. use term filter, instead of a query filter wrapping a term query).

On Wednesday, February 8, 2012 at 4:56 PM, thanuja wrote:

Hi All,
I am facing two problems in my code:
1.
I am using date histogram facet for implementing time chart. While
applying multi-filter for the facet I am facing error like Failed to
execute.
My Code is working when I am using
searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("1").facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(queryFilter(termQuery("mediatypeid","1"))));

But if I place this code inside a for loop for changing mediatypeid
value like
String mediatypeArray[i]={1,2,3,4};
for(int i=0; i<mediatypeArray[i];i++)
{
searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("daterange"+mediatypeArray[i]).facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(queryFilter(termQuery("mediatypeid",mediatypeArray[i]))));
}

The above mediatypeArray contains a set of mediatype ids

And also I cant able to apply filter for this facet.

  1. I need a time line graph for number of posts for particular date
    I need a facet like

"date e.g(1328054400000)" : {
"_type" : "date_histogram",
"entries" : [ {
"term" : 1,
"count" : 4
}]
}

but I am getting like this,
"print" : {
"_type" : "date_histogram",
"entries" : [ {
"time" : 1328054400000,
"count" : 4
}, {
"time" : 1328140800000,
"count" : 1
}, {
"time" : 1328227200000,
"count" : 1
}, {
"time" : 1328400000000,
"count" : 1
}, {
"time" : 1328486400000,
"count" : 4
}, {
"time" : 1328572800000,
"count" : 3
}, {
"time" : 1328659200000,
"count" : 1
} ]
}

Could you please help in this?.Hope I will resolve my problem soon.
Thanks in advance,

Thanuja

Hi Shay,

Thanks for your immediate response.

I have changed my code like:

searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("1").facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(termFilter("mediatypeid","1")));

searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("2").facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(termFilter("mediatypeid","2")));

It is working fine......

But if I use inside for loop It is throwing exception

for(int i=0;i<mediaTypeHistArray.length;i++)
{
searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("daterange"+mediaTypeHistArray[i]).facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(termFilter("mediatypeid",mediaTypeHistArray[i])));
}

org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to
execute phase [fetch], [reduce] Exception.

Is there any option to filter the facet using filterbuilder ?

Am I doing anything wrong? Why this code works fine for separate filters?
and not inside for loop?. Please correct me if I am wrong .

Once again thank u very much for ur timely help Shay!

-Thanuja

I still don't understand what working find for you means.., you call facetFilter twice on the same facet (it won't break things, the last one will simply be used). Can you check in the logs on the servers and gist the full failure.

On Thursday, February 9, 2012 at 10:40 AM, thanuja gandhi wrote:

Hi Shay,

Thanks for your immediate response.

I have changed my code like:

searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("1").facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(termFilter("mediatypeid","1")));

searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("2").facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(termFilter("mediatypeid","2")));

It is working fine......

But if I use inside for loop It is throwing exception

for(int i=0;i<mediaTypeHistArray.length;i++)
{
searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("daterange"+mediaTypeHistArray[i]).facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(termFilter("mediatypeid",mediaTypeHistArray[i])));
}

org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to execute phase [fetch], [reduce] Exception.

Is there any option to filter the facet using filterbuilder ?

Am I doing anything wrong? Why this code works fine for separate filters? and not inside for loop?. Please correct me if I am wrong .

Once again thank u very much for ur timely help Shay!

-Thanuja

Hi Shay,

Thanks. I have got it clear from one of our ES User posts.

http://groups.google.com/group/elasticsearch/browse_thread/thread/b52819354e9bf3ba/09852b66cdf67cb5?lnk=gst&q=Rich#09852b66cdf67cb5
.

On Sun, Feb 12, 2012 at 4:31 PM, Shay Banon kimchy@gmail.com wrote:

I still don't understand what working find for you means.., you call
facetFilter twice on the same facet (it won't break things, the last one
will simply be used). Can you check in the logs on the servers and gist the
full failure.

On Thursday, February 9, 2012 at 10:40 AM, thanuja gandhi wrote:

Hi Shay,

Thanks for your immediate response.

I have changed my code like:

searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("1").facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(termFilter("mediatypeid","1")));

searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("2").facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(termFilter("mediatypeid","2")));

It is working fine......

But if I use inside for loop It is throwing exception

for(int i=0;i<mediaTypeHistArray.length;i++)
{

searchRequestBuilder.addFacet(FacetBuilders.dateHistogramFacet("daterange"+mediaTypeHistArray[i]).facetFilter(finalFilter).field("harvesttime").interval("day").facetFilter(termFilter("mediatypeid",mediaTypeHistArray[i])));
}

org.elasticsearch.action.search.ReduceSearchPhaseException: Failed to
execute phase [fetch], [reduce] Exception.

Is there any option to filter the facet using filterbuilder ?

Am I doing anything wrong? Why this code works fine for separate filters?
and not inside for loop?. Please correct me if I am wrong .

Once again thank u very much for ur timely help Shay!

-Thanuja