Querying the results of a FilteredQuery


(Allison A.) #1

Hello ElasticSearch friends,

I have come to a dilemma. Forgive me if I am a QueryDSL newbie, but is
there a way to do a scored "match" query against the results of a filtered
query? I know filtered queries do not return boost.

Effectively I would like to return text relevancy filtered down by geo
distance.

Here is the query set up in C# code (although it should make sense for
everyone!):

        var json = new {
            query = new {
                filtered = new {
                    query = new {
                        //match_all = new { }
                        query_string = new {
                            fields = new string[] {
                                "BusinessName^1.0", "Teaser^0.2", 

"ReviewText^0.7",
"CategoryMajor^2.0",
"CategoryMinor^0.5",
"State^0.5", "City^0.5"
},
query = "restaurants",
use_dis_max = true
}
},
filter = new {
geo_distance = new {
distance = "100mi",
Location = "40.748470,-73.939180"
}
}
}
},
sort = new {
_geo_distance = new {
Location = "40.748470,-73.939180",
order = "asc",
unit = "mi"
}
},
from = 0,
size = 5
};

How do I get it to now sort by score??

Thanks,

Allison

--


(Allison A.) #2

I don't know if I explained this well.

I feel like the results I am getting are showing sort by distance, but not
also taking into account the relevancy of the text. Like, I am getting back
a dance studio with one instance of "restaurant" in "CategoryMajor" as
prioritized over a restaurant with "restaurant restaurant restaurant
restaurant" in CategoryMajor, because of the distance.

I want a sort that takes into account relevancy AND distance in the
weighting.

On Friday, September 7, 2012 12:02:12 PM UTC-4, Allison A. wrote:

Hello ElasticSearch friends,

I have come to a dilemma. Forgive me if I am a QueryDSL newbie, but is
there a way to do a scored "match" query against the results of a filtered
query? I know filtered queries do not return boost.

Effectively I would like to return text relevancy filtered down by geo
distance.

Here is the query set up in C# code (although it should make sense for
everyone!):

        var json = new {
            query = new {
                filtered = new {
                    query = new {
                        //match_all = new { }
                        query_string = new {
                            fields = new string[] {
                                "BusinessName^1.0", "Teaser^0.2", 

"ReviewText^0.7",
"CategoryMajor^2.0",
"CategoryMinor^0.5",
"State^0.5", "City^0.5"
},
query = "restaurants",
use_dis_max = true
}
},
filter = new {
geo_distance = new {
distance = "100mi",
Location = "40.748470,-73.939180"
}
}
}
},
sort = new {
_geo_distance = new {
Location = "40.748470,-73.939180",
order = "asc",
unit = "mi"
}
},
from = 0,
size = 5
};

How do I get it to now sort by score??

Thanks,

Allison

--


(phill) #3

You can add extra fields to short by, but in your case maybe what you
really want is to NOT sort by location, but instead sort by score.
You have already filtered by distance and then matched as appropriate
then filtered.

-Paul

On 9/7/2012 9:26 AM, Allison A. wrote:

                sort = new {
                    _geo_distance = new {
                        Location = "40.748470,-73.939180",
                        order = "asc",
                        unit = "mi"
                    }
                },
                from = 0,
                size = 5
            };

How do I get it to now sort by score??

--


(system) #4