# Help Understanding custom\_filters\_score Error

**URL:** <https://discuss.elastic.co/t/help-understanding-custom-filters-score-error/11793>\
**Category:** Elasticsearch\
**Created:** [May 3, 2013, 5:10am UTC](https://discuss.elastic.co/t/help-understanding-custom-filters-score-error/11793 "2013-05-03T05:10:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_5/32/1763_2.png) [@Chris\_5](https://discuss.elastic.co/u/Chris_5)\
**Post date:** [May 3, 2013, 5:10am UTC](https://discuss.elastic.co/t/help-understanding-custom-filters-score-error/11793/1 "2013-05-03T05:10:08Z")

</div>

Hi All,

I'm attempting to convert an OR filter query over to a custom\_filters\_score  
query, as I want to boost certain combinations of results higher.

Each document has three name fields, and I want to match any document that  
has a specific name in any of the fields (and boost higher if it matches  
multiple name fields), but increase the boosting even more if it matches a  
specific name field AND a set of address fields. I can't seem to see where  
I'm making the mistake, and will admit I probably have completely missed  
the mark on the query.

My attempt to re-write this query has resulted in an error, which I'll give  
first - and then the query:

nested: QueryParsingException[[cases] [\_na] filter malformed, no field after start\_object

And, here is the query:

{  
"query": {  
"custom\_filters\_score": {  
"query": {  
"match\_all": {

```
    }
  },
  "score_mode": "multiply",
  "filters": [
    {
      "boost": "1.2",
      "filter": {
        "fquery": {
          "_name": "name1",
          "query": {
            "field": {
              "name1": "John AND Doe"
            }
          }
        }
      }
    },
    {
      "boost": "1.2",
      "filter": {
        "fquery": {
          "_name": "name2",
          "query": {
            "field": {
              "name2": "John AND Doe"
            }
          }
        }
      }
    },
    {
      "boost": "1.2",
      "filter": {
        "and": [
          {
            "fquery": {
              "_name": "name3",
              "query": {
                "field": {
                  "name3": "John AND Doe"
                }
              }
            }
          }
        ]
      }
    },
    {
      "filter": {
        "boost": "1.5",
        "and": [
          {
            "query": {
              "field": {
                "zip": "77001"
              }
            }
          },
          {
            "query": {
              "field": {
                "city": "Houston"
              }
            }
          },
          {
            "query": {
              "field": {
                "address_1": "111 AND Main AND Street"
              }
            }
          },
          {
            "query": {
              "field": {
                "state": "TX"
              }
            }
          },
          {
            "fquery": {
              "_name": "name3",
              "query": {
                "field": {
                  "name3": "John AND Doe"
                }
              }
            }
          }
        ]
      }
    }
  ]
}

```

},  
"size": 200  
}

Note: I use fquery's as it is very important that I know which filter matched, for handling the results.

Am I completely off-base on the use of custom\_filters\_score here?

Thanks in advance!

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Chris\_5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_5/32/1763_2.png) [@Chris\_5](https://discuss.elastic.co/u/Chris_5)\
**Post date:** [May 3, 2013, 5:26am UTC](https://discuss.elastic.co/t/help-understanding-custom-filters-score-error/11793/2 "2013-05-03T05:26:52Z")

</div>

Of course, posting in public results in me (finally) seeing the obvious  
error:

"filter": {  
"boost": "1.5",

Should be:

"boost": "1.5",  
"filter": {

However, unlike my previous OR filter, which only returned results which matched one of the filters, now it returns all records (with the right records boosted to the top) - even those that don't match any filters?

Is it possible to replicate the behavior of an OR filter query with a customer\_filters\_score query?

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![James\_Martin](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@James\_Martin](https://discuss.elastic.co/u/James_Martin)\
**Post date:** [February 27, 2014, 6:11am UTC](https://discuss.elastic.co/t/help-understanding-custom-filters-score-error/11793/3 "2014-02-27T06:11:09Z")

</div>

Hi Chris,

I'm in the same boat; looking to combine an "or filter" (so 1 or the other  
filter matches) with a custom\_filters\_score in order to boost results which  
meet a certain criteria.  
Did you have any luck solving this?

On Friday, 3 May 2013 15:26:52 UTC+10, Chris wrote:

> Of course, posting in public results in me (finally) seeing the obvious  
> error:
> 
> "filter": {  
> "boost": "1.5",
> 
> Should be:
> 
> "boost": "1.5",  
> "filter": {
> 
> However, unlike my previous OR filter, which only returned results which matched one of the filters, now it returns all records (with the right records boosted to the top) - even those that don't match any filters?
> 
> Is it possible to replicate the behavior of an OR filter query with a customer\_filters\_score query?

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/11ab4355-3dbd-4809-a61d-f8ffc5c28686%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/11ab4355-3dbd-4809-a61d-f8ffc5c28686%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [February 27, 2014, 2:17pm UTC](https://discuss.elastic.co/t/help-understanding-custom-filters-score-error/11793/4 "2014-02-27T14:17:03Z")

</div>

You should be able to put your "overall query" into the top query part of  
your custom\_filters\_score. FYI, the function\_score should now be used in ES  
1.0. The function\_score has the flexibility to either augment your top  
level query scores, or replace them if needed - check the boost\_mode  
parameter.

[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/96772985-ccd7-47b5-abd5-c84b6b932eef%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/96772985-ccd7-47b5-abd5-c84b6b932eef%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Chris\_5](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_5/32/1763_2.png) [@Chris\_5](https://discuss.elastic.co/u/Chris_5)\
**Post date:** [February 27, 2014, 2:24pm UTC](https://discuss.elastic.co/t/help-understanding-custom-filters-score-error/11793/5 "2014-02-27T14:24:36Z")

</div>

James,

It's been a little while, but if my memory serves me correctly, the correct  
solution is that 'filters' and 'query' must be at the same level in the  
custom\_filters\_score query and you still need a filtering or limiting query  
in the query section, e.g.:

custom\_filters\_score : {  
query : {  
filtered: {  
filter : {  
or : \<--- your record matching filters go here  
},  
query : { } \<--- or you can issue a query here  
},  
score\_mode : 'score\_multiply',  
filters : [ \<--- your boost filters go here  
{  
boost : '1.5',  
filter : {  
and :   
}  
},  
...  
]  
}

The problem in the query I posted in my original message is that I was  
trying to get the scoring filters to do the record filtering, which they  
don't.

On Thu, Feb 27, 2014 at 12:11 AM, James Martin [jamsii@gmail.com](mailto:jamsii@gmail.com) wrote:

> Hi Chris,
> 
> I'm in the same boat; looking to combine an "or filter" (so 1 or the other  
> filter matches) with a custom\_filters\_score in order to boost results which  
> meet a certain criteria.  
> Did you have any luck solving this?
> 
> On Friday, 3 May 2013 15:26:52 UTC+10, Chris wrote:
> 
> > Of course, posting in public results in me (finally) seeing the obvious  
> > error:
> > 
> > "filter": {  
> > "boost": "1.5",
> > 
> > Should be:
> > 
> > "boost": "1.5",  
> > "filter": {
> > 
> > However, unlike my previous OR filter, which only returned results which matched one of the filters, now it returns all records (with the right records boosted to the top) - even those that don't match any filters?
> > 
> > Is it possible to replicate the behavior of an OR filter query with a customer\_filters\_score query?
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/zXCnWFEW7bE/unsubscribe](https://groups.google.com/d/topic/elasticsearch/zXCnWFEW7bE/unsubscribe).
> 
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/11ab4355-3dbd-4809-a61d-f8ffc5c28686%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/11ab4355-3dbd-4809-a61d-f8ffc5c28686%40googlegroups.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKVTPE36Ht96CNXNCcDJa67G9moXGkh76PfWrFg\_KdZSOsHokQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKVTPE36Ht96CNXNCcDJa67G9moXGkh76PfWrFg_KdZSOsHokQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![jdepp99](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@jdepp99](https://discuss.elastic.co/u/jdepp99)\
**Post date:** [February 27, 2014, 4:42pm UTC](https://discuss.elastic.co/t/help-understanding-custom-filters-score-error/11793/6 "2014-02-27T16:42:37Z")

</div>

Just trying to figure out where these custom queries get created? In Elasticsearch or can it be done in kibana interface?

---

<div class="post-metadata">

**Author:** ![James\_Martin](https://avatars.discourse-cdn.com/v4/letter/j/f14d63/32.png) [@James\_Martin](https://discuss.elastic.co/u/James_Martin)\
**Post date:** [February 28, 2014, 1:27am UTC](https://discuss.elastic.co/t/help-understanding-custom-filters-score-error/11793/7 "2014-02-28T01:27:26Z")

</div>

Hi Chris,

Thanks for getting back to me. Originally had trouble getting your example to work, but after reading your statement;

```
"the correct solution is that 'filters' and 'query' must be at the same level"

```

I realised your example didn’t have them at the same level, oops! Once I sorted that, things started to work.  
Once again, thanks.

James

On 28 February 2014 at 1:24:42 am, Chris Church ([thisdroneeatspeople@gmail.com](mailto:thisdroneeatspeople@gmail.com)) wrote:

James,

It's been a little while, but if my memory serves me correctly, the correct solution is that 'filters' and 'query' must be at the same level in the custom\_filters\_score query and you still need a filtering or limiting query in the query section, e.g.:

custom\_filters\_score : {  
query : {  
filtered: {  
filter : {  
or : [] \<--- your record matching filters go here  
},  
query : { } \<--- or you can issue a query here  
},  
score\_mode : 'score\_multiply',  
filters : [ \<--- your boost filters go here  
{  
boost : '1.5',  
filter : {  
and : []  
}  
},  
...  
]  
}

The problem in the query I posted in my original message is that I was trying to get the scoring filters to do the record filtering, which they don't.

On Thu, Feb 27, 2014 at 12:11 AM, James Martin [jamsii@gmail.com](mailto:jamsii@gmail.com) wrote:  
Hi Chris,

I'm in the same boat; looking to combine an "or filter" (so 1 or the other filter matches) with a custom\_filters\_score in order to boost results which meet a certain criteria.  
Did you have any luck solving this?

On Friday, 3 May 2013 15:26:52 UTC+10, Chris wrote:  
Of course, posting in public results in me (finally) seeing the obvious error:

"filter": {  
"boost": "1.5",

Should be:

"boost": "1.5",  
"filter": {

However, unlike my previous OR filter, which only returned results which matched one of the filters, now it returns all records (with the right records boosted to the top) - even those that don't match any filters?

## Is it possible to replicate the behavior of an OR filter query with a customer\_filters\_score query?

You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/zXCnWFEW7bE/unsubscribe](https://groups.google.com/d/topic/elasticsearch/zXCnWFEW7bE/unsubscribe).

To unsubscribe from this group and all its topics, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/11ab4355-3dbd-4809-a61d-f8ffc5c28686%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/11ab4355-3dbd-4809-a61d-f8ffc5c28686%40googlegroups.com).

For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to a topic in the Google Groups "elasticsearch" group.  
To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/zXCnWFEW7bE/unsubscribe](https://groups.google.com/d/topic/elasticsearch/zXCnWFEW7bE/unsubscribe).  
To unsubscribe from this group and all its topics, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKVTPE36Ht96CNXNCcDJa67G9moXGkh76PfWrFg\_KdZSOsHokQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKVTPE36Ht96CNXNCcDJa67G9moXGkh76PfWrFg_KdZSOsHokQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.530fe5fe.515f007c.143%40J.local](https://groups.google.com/d/msgid/elasticsearch/etPan.530fe5fe.515f007c.143%40J.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:46am UTC](https://discuss.elastic.co/t/help-understanding-custom-filters-score-error/11793/8 "2017-07-06T01:46:43Z")

</div>


