I am working on this query which involves term match of around 100 queries with "should" clause. It goes something like this.
"query": {
"function_score": {
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"match_all": [
]
}
],
"should": [
{
"match": {
"product_id": {
"query": "1234",
"boost": 15750
}
}
},
{
"match": {
"product_id": {
"query": "83127",
"boost": 13446
}
}
},
{
"match": {
"product_id": {
"query": "3123",
"boost": 6894
}
}
},
{
"match": {
"product_id": {
"query": "43243",
"boost": 6246
}
}
},
{
"match": {
"product_id": {
"query": "645464",
"boost": 6102
}
}
},
{
"match": {
"product_id": {
"query": "757563",
"boost": 5814
}
...
where the should clause is around 100 queries. The idea being differential boost for the products in our custom ranking algorithm.
However I see the steep rise in the CPU load. Is there any way we can optimize this?
The mapping for product_id field is:
'product_id' => [
'type' => 'string',
'index' => 'not_analyzed',
]