# Custom Score

**URL:** <https://discuss.elastic.co/t/custom-score/7518>\
**Category:** Elasticsearch\
**Created:** [May 1, 2012, 2:29am UTC](https://discuss.elastic.co/t/custom-score/7518 "2012-05-01T02:29:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brandon\_Hilkert](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_hilkert/32/2182_2.png) [@Brandon\_Hilkert](https://discuss.elastic.co/u/Brandon_Hilkert)\
**Post date:** [May 1, 2012, 2:29am UTC](https://discuss.elastic.co/t/custom-score/7518/1 "2012-05-01T02:29:29Z")

</div>

I'm using Elastic Search to index user documents. We're looking to  
implement a custom score based on the closeness of other users. So we'll  
compare one user to another. Each user has the following fields:

interests: ["Lucene", "ElasticSearch"...]

_Python Script_  
len(set(interests).intersection(set(doc['interests'].value)))

The script is attempting to find the common interests between the two  
people, however it keeps giving an error. I'm using the Ruby Tire gem,  
which produces the following command:

[REQUEST FAILED] curl -X GET  
"[http://localhost:9200/users/user/\_search?pretty=true](http://localhost:9200/users/user/_search?pretty=true)" -d  
'{"query":{"custom\_score":{"params":{"interests":["Entrepreneurship","Travel","Technology","Startups"]},"script":"meeteor","lang":"python","query":{"bool":{"should":[{"query\_string":{"query":"jobs.employer:Facebook","default\_operator":"AND"}},{"query\_string":{"query":"jobs.employer:AOL","default\_operator":"AND"}},{"query\_string":{"query":"experienced\_industries:Computer  
Software","default\_operator":"AND"}},{"query\_string":{"query":"experienced\_industries:Internet","default\_operator":"AND"}}]}}}},"filter":{"and":[{"term":{"is\_active":1}},{"term":{"is\_email\_confirmed":1}}]}}'  
Tire::Search::SearchRequestFailed: 500 :  
{"error":"SearchPhaseExecutionException[Failed to execute phase [query],  
total failure; shardFailures {[7WFRorBIQoiuD2kl\_RXGfQ][users][1]:  
QueryPhaseExecutionException[[users][1]: query[filtered(custom score  
(jobs.employer:facebook jobs.employer:aol (+experienced\_industries:computer  
+\_all:software) experienced\_industries:internet,function=script[meeteor],  
params [{interests=[Entrepreneurship, Travel, Technology,  
Startups]}]))-\>cache(\_type:user)],from[0],size[10]: Query Failed [Failed to  
execute main query]]; nested: }{[7WFRorBIQoiuD2kl\_RXGfQ][users][2]:  
QueryPhaseExecutionException[[users][2]: query[filtered(custom score  
(jobs.employer:facebook jobs.employer:aol (+experienced\_industries:computer  
+\_all:software) experienced\_industries:internet,function=script[meeteor],  
params [{interests=[Entrepreneurship, Travel, Technology,  
Startups]}]))-\>cache(\_type:user)],from[0],size[10]: Query Failed [Failed to  
execute main query]]; nested: }]","status":500}

Any idea what's wrong?

---

<div class="post-metadata">

**Author:** ![Brandon\_Hilkert](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_hilkert/32/2182_2.png) [@Brandon\_Hilkert](https://discuss.elastic.co/u/Brandon_Hilkert)\
**Post date:** [May 1, 2012, 2:32am UTC](https://discuss.elastic.co/t/custom-score/7518/2 "2012-05-01T02:32:41Z")

</div>

Here's a formatted view of the json:

{  
"query":{  
"custom\_score":{  
"params":{  
"interests":[  
"Entrepreneurship",  
"Travel",  
"Technology",  
"Startups"  
]  
},  
"script":"meeteor",  
"lang":"python",  
"query":{  
"bool":{  
"should":[  
{  
"query\_string":{  
"query":"jobs.employer:Facebook",  
"default\_operator":"AND"  
}  
},  
{  
"query\_string":{  
"query":"jobs.employer:AOL",  
"default\_operator":"AND"  
}  
},  
{  
"query\_string":{  
"query":"experienced\_industries:Computer Software",  
"default\_operator":"AND"  
}  
},  
{  
"query\_string":{  
"query":"experienced\_industries:Internet",  
"default\_operator":"AND"  
}  
}  
]  
}  
}  
}  
},  
"filter":{  
"and":[  
{  
"term":{  
"is\_active":1  
}  
},  
{  
"term":{  
"is\_email\_confirmed":1  
}  
}  
]  
}  
}

On Monday, April 30, 2012 10:29:29 PM UTC-4, Brandon Hilkert wrote:

> I'm using Elastic Search to index user documents. We're looking to  
> implement a custom score based on the closeness of other users. So we'll  
> compare one user to another. Each user has the following fields:
> 
> interests: ["Lucene", "Elasticsearch"...]
> 
> _Python Script_  
> len(set(interests).intersection(set(doc['interests'].value)))
> 
> The script is attempting to find the common interests between the two  
> people, however it keeps giving an error. I'm using the Ruby Tire gem,  
> which produces the following command:
> 
> [REQUEST FAILED] curl -X GET "  
> [http://localhost:9200/users/user/\_search?pretty=true](http://localhost:9200/users/user/_search?pretty=true)" -d  
> '{"query":{"custom\_score":{"params":{"interests":["Entrepreneurship","Travel","Technology","Startups"]},"script":"meeteor","lang":"python","query":{"bool":{"should":[{"query\_string":{"query":"jobs.employer:Facebook","default\_operator":"AND"}},{"query\_string":{"query":"jobs.employer:AOL","default\_operator":"AND"}},{"query\_string":{"query":"experienced\_industries:Computer  
> Software","default\_operator":"AND"}},{"query\_string":{"query":"experienced\_industries:Internet","default\_operator":"AND"}}]}}}},"filter":{"and":[{"term":{"is\_active":1}},{"term":{"is\_email\_confirmed":1}}]}}'  
> Tire::Search::SearchRequestFailed: 500 :  
> {"error":"SearchPhaseExecutionException[Failed to execute phase [query],  
> total failure; shardFailures {[7WFRorBIQoiuD2kl\_RXGfQ][users][1]:  
> QueryPhaseExecutionException[[users][1]: query[filtered(custom score  
> (jobs.employer:facebook jobs.employer:aol (+experienced\_industries:computer  
> +\_all:software) experienced\_industries:internet,function=script[meeteor],  
> params [{interests=[Entrepreneurship, Travel, Technology,  
> Startups]}]))-\>cache(\_type:user)],from[0],size[10]: Query Failed [Failed to  
> execute main query]]; nested: }{[7WFRorBIQoiuD2kl\_RXGfQ][users][2]:  
> QueryPhaseExecutionException[[users][2]: query[filtered(custom score  
> (jobs.employer:facebook jobs.employer:aol (+experienced\_industries:computer  
> +\_all:software) experienced\_industries:internet,function=script[meeteor],  
> params [{interests=[Entrepreneurship, Travel, Technology,  
> Startups]}]))-\>cache(\_type:user)],from[0],size[10]: Query Failed [Failed to  
> execute main query]]; nested: }]","status":500}
> 
> Any idea what's wrong?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 2, 2012, 4:19pm UTC](https://discuss.elastic.co/t/custom-score/7518/3 "2012-05-02T16:19:21Z")

</div>

On the server node, you should see a the full failure in the logs, can you  
gist it?

On Tue, May 1, 2012 at 5:32 AM, Brandon Hilkert [brandon@meeteor.com](mailto:brandon@meeteor.com) wrote:

> Here's a formatted view of the json:
> 
> {  
> "query":{  
> "custom\_score":{  
> "params":{  
> "interests":[  
> "Entrepreneurship",  
> "Travel",  
> "Technology",  
> "Startups"  
> ]  
> },  
> "script":"meeteor",  
> "lang":"python",  
> "query":{  
> "bool":{  
> "should":[  
> {  
> "query\_string":{  
> "query":"jobs.employer:Facebook",  
> "default\_operator":"AND"  
> }  
> },  
> {  
> "query\_string":{  
> "query":"jobs.employer:AOL",  
> "default\_operator":"AND"  
> }  
> },  
> {  
> "query\_string":{  
> "query":"experienced\_industries:Computer Software"  
> ,  
> "default\_operator":"AND"  
> }  
> },  
> {  
> "query\_string":{  
> "query":"experienced\_industries:Internet",  
> "default\_operator":"AND"  
> }  
> }  
> ]  
> }  
> }  
> }  
> },  
> "filter":{  
> "and":[  
> {  
> "term":{  
> "is\_active":1  
> }  
> },  
> {  
> "term":{  
> "is\_email\_confirmed":1  
> }  
> }  
> ]  
> }  
> }
> 
> On Monday, April 30, 2012 10:29:29 PM UTC-4, Brandon Hilkert wrote:
> 
> > I'm using Elastic Search to index user documents. We're looking to  
> > implement a custom score based on the closeness of other users. So we'll  
> > compare one user to another. Each user has the following fields:
> > 
> > interests: ["Lucene", "Elasticsearch"...]
> > 
> > _Python Script_  
> > len(set(interests).\*\*intersection(set(doc['\*\*interests'].value)))
> > 
> > The script is attempting to find the common interests between the two  
> > people, however it keeps giving an error. I'm using the Ruby Tire gem,  
> > which produces the following command:
> > 
> > [REQUEST FAILED] curl -X GET "[http://localhost:9200/users/](http://localhost:9200/users/)\*\*  
> > user/_search?pretty=true[http://localhost:9200/users/user/\_search?pretty=true](http://localhost:9200/users/user/_search?pretty=true)"  
> > -d '{"query":{"custom\_score":{"**params":{"interests":["**  
> > Entrepreneurship","Travel","**Technology","Startups"]},"**  
> > script":"meeteor","lang":" **python","query":{"bool":{"**  
> > should":[{"query\_string":{" **query":"jobs.employer:**  
> > Facebook","default\_operator":" **AND"}},{"query\_string":{"**  
> > query":"jobs.employer:AOL"," **default\_operator":"AND"}},{"**  
> > query\_string":{"query":"\*\*experienced\_industries:\*\*Computer  
> > Software","default\_operator":" **AND"}},{"query\_string":{"**  
> > query":"experienced_ **industries:Internet","default\_**  
> > operator":"AND"}}]}}}},"**filter":{"and":[{"term":{"is\_**  
> > active":1}},{"term":{"is\_\*\*email\_confirmed":1}}]}}'  
> > Tire::Search:: **SearchRequestFailed: 500 : {"error":"**  
> > SearchPhaseExecutionException[\*\*Failed to execute phase [query], total  
> > failure; shardFailures {[7WFRorBIQoiuD2kl\_RXGfQ][\*\*users][1]:  
> > QueryPhaseExecutionException[[\*\*users][1]: query[filtered(custom score  
> > (jobs.employer:facebook jobs.employer:aol (+experienced\_industries:\*\*computer  
> > +\_all:software) experienced\_industries:\*\*internet,function=script[\*\*meeteor],  
> > params [{interests=[Entrepreneurship, Travel, Technology,  
> > Startups]}]))-\>cache(\_type:\*\*user)],from[0],size[10]: Query Failed  
> > [Failed to execute main query]]; nested: }{[7WFRorBIQoiuD2kl\_RXGfQ][\*\*users][2]:  
> > QueryPhaseExecutionException[[\*\*users][2]: query[filtered(custom score  
> > (jobs.employer:facebook jobs.employer:aol (+experienced\_industries:\*\*computer  
> > +\_all:software) experienced\_industries:\*\*internet,function=script[\*\*meeteor],  
> > params [{interests=[Entrepreneurship, Travel, Technology,  
> > Startups]}]))-\>cache(\_type:\*\*user)],from[0],size[10]: Query Failed  
> > [Failed to execute main query]]; nested: }]","status":500}
> > 
> > Any idea what's wrong?

---

<div class="post-metadata">

**Author:** ![Brandon\_Hilkert](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brandon_hilkert/32/2182_2.png) [@Brandon\_Hilkert](https://discuss.elastic.co/u/Brandon_Hilkert)\
**Post date:** [May 2, 2012, 4:35pm UTC](https://discuss.elastic.co/t/custom-score/7518/4 "2012-05-02T16:35:27Z")

</div>

Hey Shay,

I ended up sorting it out. It was due to me not using the "values" method  
when trying to compare an array field.

Thanks,  
Brandon

On Wednesday, May 2, 2012 12:19:21 PM UTC-4, kimchy wrote:

> On the server node, you should see a the full failure in the logs, can you  
> gist it?
> 
> On Tue, May 1, 2012 at 5:32 AM, Brandon Hilkert [brandon@meeteor.com](mailto:brandon@meeteor.com)wrote:
> 
> > Here's a formatted view of the json:
> > 
> > {  
> > "query":{  
> > "custom\_score":{  
> > "params":{  
> > "interests":[  
> > "Entrepreneurship",  
> > "Travel",  
> > "Technology",  
> > "Startups"  
> > ]  
> > },  
> > "script":"meeteor",  
> > "lang":"python",  
> > "query":{  
> > "bool":{  
> > "should":[  
> > {  
> > "query\_string":{  
> > "query":"jobs.employer:Facebook",  
> > "default\_operator":"AND"  
> > }  
> > },  
> > {  
> > "query\_string":{  
> > "query":"jobs.employer:AOL",  
> > "default\_operator":"AND"  
> > }  
> > },  
> > {  
> > "query\_string":{  
> > "query":  
> > "experienced\_industries:Computer Software",  
> > "default\_operator":"AND"  
> > }  
> > },  
> > {  
> > "query\_string":{  
> > "query":"experienced\_industries:Internet",  
> > "default\_operator":"AND"  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > },  
> > "filter":{  
> > "and":[  
> > {  
> > "term":{  
> > "is\_active":1  
> > }  
> > },  
> > {  
> > "term":{  
> > "is\_email\_confirmed":1  
> > }  
> > }  
> > ]  
> > }  
> > }
> > 
> > On Monday, April 30, 2012 10:29:29 PM UTC-4, Brandon Hilkert wrote:
> > 
> > > I'm using Elastic Search to index user documents. We're looking to  
> > > implement a custom score based on the closeness of other users. So we'll  
> > > compare one user to another. Each user has the following fields:
> > > 
> > > interests: ["Lucene", "Elasticsearch"...]
> > > 
> > > _Python Script_  
> > > len(set(interests).\*\*intersection(set(doc['\*\*interests'].value)))
> > > 
> > > The script is attempting to find the common interests between the two  
> > > people, however it keeps giving an error. I'm using the Ruby Tire gem,  
> > > which produces the following command:
> > > 
> > > [REQUEST FAILED] curl -X GET "[http://localhost:9200/users/](http://localhost:9200/users/)\*\*  
> > > user/_search?pretty=true[http://localhost:9200/users/user/\_search?pretty=true](http://localhost:9200/users/user/_search?pretty=true)"  
> > > -d '{"query":{"custom\_score":{"**params":{"interests":["**  
> > > Entrepreneurship","Travel","**Technology","Startups"]},"**  
> > > script":"meeteor","lang":" **python","query":{"bool":{"**  
> > > should":[{"query\_string":{" **query":"jobs.employer:**  
> > > Facebook","default\_operator":" **AND"}},{"query\_string":{"**  
> > > query":"jobs.employer:AOL"," **default\_operator":"AND"}},{"**  
> > > query\_string":{"query":"\*\*experienced\_industries:\*\*Computer  
> > > Software","default\_operator":" **AND"}},{"query\_string":{"**  
> > > query":"experienced_ **industries:Internet","default\_**  
> > > operator":"AND"}}]}}}},"**filter":{"and":[{"term":{"is\_**  
> > > active":1}},{"term":{"is\_\*\*email\_confirmed":1}}]}}'  
> > > Tire::Search:: **SearchRequestFailed: 500 : {"error":"**  
> > > SearchPhaseExecutionException[\*\*Failed to execute phase [query], total  
> > > failure; shardFailures {[7WFRorBIQoiuD2kl\_RXGfQ][\*\*users][1]:  
> > > QueryPhaseExecutionException[[\*\*users][1]: query[filtered(custom score  
> > > (jobs.employer:facebook jobs.employer:aol (+experienced\_industries:\*\*computer  
> > > +\_all:software) experienced\_industries:\*\*internet,function=script[\*\*meeteor],  
> > > params [{interests=[Entrepreneurship, Travel, Technology,  
> > > Startups]}]))-\>cache(\_type:\*\*user)],from[0],size[10]: Query Failed  
> > > [Failed to execute main query]]; nested: }{[7WFRorBIQoiuD2kl\_RXGfQ][\*\*users][2]:  
> > > QueryPhaseExecutionException[[\*\*users][2]: query[filtered(custom score  
> > > (jobs.employer:facebook jobs.employer:aol (+experienced\_industries:\*\*computer  
> > > +\_all:software) experienced\_industries:\*\*internet,function=script[\*\*meeteor],  
> > > params [{interests=[Entrepreneurship, Travel, Technology,  
> > > Startups]}]))-\>cache(\_type:\*\*user)],from[0],size[10]: Query Failed  
> > > [Failed to execute main query]]; nested: }]","status":500}
> > > 
> > > Any idea what's wrong?

---

<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, 3:30am UTC](https://discuss.elastic.co/t/custom-score/7518/5 "2017-07-06T03:30:17Z")

</div>


