Boosting certain conditions

I have the following filtered query right now:

{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "MySQL Apple"
}
},
"filter": {
"and": [
{
"term": {
"is_active": true
}
},
{
"not": {
"terms": {
"id": [
6433746,
5308541
]
}
}
},
{
"not": {
"terms": {
"linkedin_id": [
"D-D5EAmm_J",
"SxQY_1y5pA",
"Nqt6b6We2-"
]
}
}
},
{
"not": {
"terms": {
"fb_user_id": [
"120139",
"503009",
"610039"
]
}
}
}
]
}
}
},
"size": 9,
"fields": [
"id"
]
}

As you can see I need the following:

  1. Search the _all field for query text
  2. Filter out certain Facebook, Linkedin, and system users

As part of this, I would like to add the following:

Boost certain results when their field "fb_connections" contains certain
IDs that I will pass in. Likewise for the "linkedin_connections" field.

Can I still use a filtered query? If so, what might that addition look
like? If not, what is the more appropriate query type.

Thanks,
Brandon

--

Yes, you can still use filtered query. You just need to wrap your existing
query into Custom Filters Score queryhttp://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query.htmlto boost results that match certain conditions. The conditions can be
expressed as list of filters with corresponding boost factor:

{
"query": {
"filtered": {
"query": {

  •    "custom_filters_score" : {*
    
  •      "query": {*
    
  •        *"query_string": {
            "query": "MySQL Apple"
          },
    
  •        "filters" : [*
    
  •            {*
    
  •              "filter" : { "term" : { "linkedin_connections" : 
    

"DEds324ts34"} },*

  •              "boost" : "3"*
    
  •            },*
    
  •            {*
    
  •              "filter" : { "term" : { "fb_connections" : "123456"} },*
    
  •              "boost" : "2"*
    
  •            }*
    
  •        ],*
    
  •        "score_mode" : "first"            *
    
  •      }*
    },
    "filter": {
      "and": [
        {
          "term": {
            "is_active": true
          }
        },
    

........... the rest of your query .............

On Tuesday, November 6, 2012 8:06:46 AM UTC-5, Brandon Hilkert wrote:

I have the following filtered query right now:

{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "MySQL Apple"
}
},
"filter": {
"and": [
{
"term": {
"is_active": true
}
},
{
"not": {
"terms": {
"id": [
6433746,
5308541
]
}
}
},
{
"not": {
"terms": {
"linkedin_id": [
"D-D5EAmm_J",
"SxQY_1y5pA",
"Nqt6b6We2-"
]
}
}
},
{
"not": {
"terms": {
"fb_user_id": [
"120139",
"503009",
"610039"
]
}
}
}
]
}
}
},
"size": 9,
"fields": [
"id"
]
}

As you can see I need the following:

  1. Search the _all field for query text
  2. Filter out certain Facebook, Linkedin, and system users

As part of this, I would like to add the following:

Boost certain results when their field "fb_connections" contains certain
IDs that I will pass in. Likewise for the "linkedin_connections" field.

Can I still use a filtered query? If so, what might that addition look
like? If not, what is the more appropriate query type.

Thanks,
Brandon

--

Thanks Igor. Would I still get results that are outside the filter? I
really just want that boosting to strengthen the results, but don't want it
to limit it to just those.

On Tue, Nov 6, 2012 at 5:53 PM, Igor Motov imotov@gmail.com wrote:

Yes, you can still use filtered query. You just need to wrap your existing
query into Custom Filters Score queryhttp://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query.htmlto boost results that match certain conditions. The conditions can be
expressed as list of filters with corresponding boost factor:

{
"query": {
"filtered": {
"query": {

  •    "custom_filters_score" : {*
    
  •      "query": {*
    
  •        *"query_string": {
            "query": "MySQL Apple"
          },
    
  •        "filters" : [*
    
  •            {*
    
  •              "filter" : { "term" : { "linkedin_connections" :
    

"DEds324ts34"} },*

  •              "boost" : "3"*
    
  •            },*
    
  •            {*
    
  •              "filter" : { "term" : { "fb_connections" : "123456"} },
    
  •              "boost" : "2"*
    
  •            }*
    
  •        ],*
    
  •        "score_mode" : "first"            *
    
  •      }*
    },
    "filter": {
      "and": [
        {
          "term": {
            "is_active": true
          }
        },
    

........... the rest of your query .............

On Tuesday, November 6, 2012 8:06:46 AM UTC-5, Brandon Hilkert wrote:

I have the following filtered query right now:

{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "MySQL Apple"
}
},
"filter": {
"and": [
{
"term": {
"is_active": true
}
},
{
"not": {
"terms": {
"id": [
6433746,
5308541
]
}
}
},
{
"not": {
"terms": {
"linkedin_id": [
"D-D5EAmm_J",
"SxQY_1y5pA",
"Nqt6b6We2-"
]
}
}
},
{
"not": {
"terms": {
"fb_user_id": [
"120139",
"503009",
"610039"
]
}
}
}
]
}
}
},
"size": 9,
"fields": [
"id"
]
}

As you can see I need the following:

  1. Search the _all field for query text
  2. Filter out certain Facebook, Linkedin, and system users

As part of this, I would like to add the following:

Boost certain results when their field "fb_connections" contains certain
IDs that I will pass in. Likewise for the "linkedin_connections" field.

Can I still use a filtered query? If so, what might that addition look
like? If not, what is the more appropriate query type.

Thanks,
Brandon

--

--

Yes, this is what Custom Filters Score is doing. It uses these filters to
boost results, not to limit them.

On Tuesday, November 6, 2012 6:07:54 PM UTC-5, Brandon Hilkert wrote:

Thanks Igor. Would I still get results that are outside the filter? I
really just want that boosting to strengthen the results, but don't want it
to limit it to just those.

On Tue, Nov 6, 2012 at 5:53 PM, Igor Motov <imo...@gmail.com <javascript:>

wrote:

Yes, you can still use filtered query. You just need to wrap your
existing query into Custom Filters Score queryhttp://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query.htmlto boost results that match certain conditions. The conditions can be
expressed as list of filters with corresponding boost factor:

{
"query": {
"filtered": {
"query": {

  •    "custom_filters_score" : {*
    
  •      "query": {*
    
  •        *"query_string": {
            "query": "MySQL Apple"
          },
    
  •        "filters" : [*
    
  •            {*
    
  •              "filter" : { "term" : { "linkedin_connections" : 
    

"DEds324ts34"} },*

  •              "boost" : "3"*
    
  •            },*
    
  •            {*
    
  •              "filter" : { "term" : { "fb_connections" : "123456"} 
    

},*

  •              "boost" : "2"*
    
  •            }*
    
  •        ],*
    
  •        "score_mode" : "first"            *
    
  •      }*
    },
    "filter": {
      "and": [
        {
          "term": {
            "is_active": true
          }
        },
    

........... the rest of your query .............

On Tuesday, November 6, 2012 8:06:46 AM UTC-5, Brandon Hilkert wrote:

I have the following filtered query right now:

{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "MySQL Apple"
}
},
"filter": {
"and": [
{
"term": {
"is_active": true
}
},
{
"not": {
"terms": {
"id": [
6433746,
5308541
]
}
}
},
{
"not": {
"terms": {
"linkedin_id": [
"D-D5EAmm_J",
"SxQY_1y5pA",
"Nqt6b6We2-"
]
}
}
},
{
"not": {
"terms": {
"fb_user_id": [
"120139",
"503009",
"610039"
]
}
}
}
]
}
}
},
"size": 9,
"fields": [
"id"
]
}

As you can see I need the following:

  1. Search the _all field for query text
  2. Filter out certain Facebook, Linkedin, and system users

As part of this, I would like to add the following:

Boost certain results when their field "fb_connections" contains certain
IDs that I will pass in. Likewise for the "linkedin_connections" field.

Can I still use a filtered query? If so, what might that addition look
like? If not, what is the more appropriate query type.

Thanks,
Brandon

--

--