# Need help in tuning score query using wildcards

**URL:** <https://discuss.elastic.co/t/need-help-in-tuning-score-query-using-wildcards/26230>\
**Category:** Elasticsearch\
**Created:** [July 24, 2015, 10:48am UTC](https://discuss.elastic.co/t/need-help-in-tuning-score-query-using-wildcards/26230 "2015-07-24T10:48:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shishir\_Shikarkhane](https://avatars.discourse-cdn.com/v4/letter/s/8e7dd6/32.png) [@Shishir\_Shikarkhane](https://discuss.elastic.co/u/Shishir_Shikarkhane)\
**Post date:** [July 24, 2015, 10:48am UTC](https://discuss.elastic.co/t/need-help-in-tuning-score-query-using-wildcards/26230/1 "2015-07-24T10:48:15Z")

</div>

Hello ,  
We have a requirement wherein we have to make a contains search on 3 fields "ITEM\_NUMBER" , "DESCRIPTION" and "MAJOR\_FAMILY\_NAME" .  
Search should always return 100 records where searching preference is like

1. ITEM\_NUMBER 2.DESCRIPTION 3. MAJOR\_FAMILY\_NAME  
We need records to be sorted based on the match .  
That means records with a matching ITEM\_NUMBER should be at top .

We are using Custom score query for it as below .  
Query takes almost 4-5 seconds and is very slow .  
Index size is close to 34 million records and each record has 40 fields .

We seek expert suggestions on tuning this query .  
Appreciate any inputs on performance improvement

{  
"filtered" : {  
"query" : {  
"function\_score" : {  
"filter" : {  
"bool" : {  
"should" : [ {  
"query" : {  
"wildcard" : {  
"ITEM\_NUMBER" : {  
"wildcard" : "_searchstring_"  
}  
}  
}  
}, {  
"query" : {  
"wildcard" : {  
"DESCRIPTION" : {  
"wildcard" : "_searchstring_"  
}  
}  
}  
}, {  
"query" : {  
"wildcard" : {  
"MAJOR\_FAMILY\_NAME" : {  
"wildcard" : "_searchstring_"  
}  
}  
}  
} ]  
}  
},  
"functions" : [ {  
"filter" : {  
"query" : {  
"wildcard" : {  
"ITEM\_NUMBER" : {  
"wildcard" : "_searchstring_"  
}  
}  
}  
},  
"boost\_factor" : 5.0  
}, {  
"filter" : {  
"query" : {  
"wildcard" : {  
"DESCRIPTION" : {  
"wildcard" : "_searchstring_"  
}  
}  
}  
},  
"boost\_factor" : 2.0  
}, {  
"filter" : {  
"query" : {  
"wildcard" : {  
"MAJOR\_FAMILY\_NAME" : {  
"wildcard" : "_searchstring_"  
}  
}  
}  
},  
"boost\_factor" : 1.0  
} ],  
"score\_mode" : "sum",  
"boost\_mode" : "replace"  
}  
},  
"filter" : {  
"and" : {  
"filters" : [ {  
"bool" : {  
"must\_not" : {  
"query" : {  
"term" : {  
"IS\_NPI\_ENABLED" : "Y"  
}  
}  
}  
}  
}, {  
"query" : {  
"term" : {  
"ERP\_PRICE\_LIST\_ID" : 1109  
}  
}  
}, {  
"query" : {  
"term" : {  
"DISTI\_ONLY\_SKU" : "N"  
}  
}  
}, {  
"query" : {  
"term" : {  
"SERVICE\_FLAG\_C" : "N"  
}  
}  
}, {  
"bool" : {  
"should" : {  
"bool" : {  
"must" : {  
"or" : {  
"filters" : [ {  
"query" : {  
"term" : {  
"PUBLISHED\_TO\_PRICING\_FLAG" : "Y"  
}  
}  
}, {  
"missing" : {  
"field" : "PUBLISHED\_TO\_PRICING\_FLAG"  
}  
} ]  
}  
},  
"must\_not" : {  
"query" : {  
"term" : {  
"VIEW\_NAME" : "CO\_LIMITED\_ITEM\_MASTER\_VW"  
}  
}  
}  
}  
}  
}  
} ]  
}  
}  
}  
}

---

<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 5, 2017, 11:59pm UTC](https://discuss.elastic.co/t/need-help-in-tuning-score-query-using-wildcards/26230/2 "2017-07-05T23:59:18Z")

</div>


