# Delay in response after using function\_score for sorting of documents according to field match

**URL:** <https://discuss.elastic.co/t/delay-in-response-after-using-function-score-for-sorting-of-documents-according-to-field-match/280113>\
**Category:** Elasticsearch\
**Created:** [July 31, 2021, 6:09am UTC](https://discuss.elastic.co/t/delay-in-response-after-using-function-score-for-sorting-of-documents-according-to-field-match/280113 "2021-07-31T06:09:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AshuCh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashuch/32/92375_2.png) [@AshuCh](https://discuss.elastic.co/u/AshuCh)\
**Post date:** [July 31, 2021, 6:09am UTC](https://discuss.elastic.co/t/delay-in-response-after-using-function-score-for-sorting-of-documents-according-to-field-match/280113/1 "2021-07-31T06:09:55Z")

</div>

When using function\_score to sort the document on base of score response is taking too much time to come it's in minutes. The problem is I need sorting according to fields. When using boost not getting the relevant data.

query I'm using is as follow:

```auto
function_score.functions[
/ *********registered indian user exact match******** /
        {
          "filter": {
            "bool": {
              "must": [
                {
                  "exists": {
                    "field": "userId"
                  }
                },
                {
                  "exists": {
                    "field": "location.country"
                  }
                },
                {
                  "match": {
                    "location.country.name": "india"
                  }
                },
                {
                  "wildcard": {
                    "keywords.keyword": `${p}`
                  }
                }
              ]
            }
          },
          "weight": 10
        },
        / *********registered indian user partial match******** /
        {
          "filter": {
            "bool": {
              "must": [
                {
                  "exists": {
                    "field": "userId"
                  }
                },
                {
                  "exists": {
                    "field": "location.country"
                  }
                },
                {
                  "match": {
                    "location.country.name": "india"
                  }
                },
                {
                  "wildcard": {
                    "keywords.keyword": `*${p}*`
                  }
                }
              ]
            }
          },
          "weight": 15
        },

        / *********registered foreign user exact match******** /
        {
          "filter": {
            "bool": {
              "must": [
                {
                  "exists": {
                    "field": "userId"
                  }
                },
                {
                  "exists": {
                    "field": "location.country"
                  }
                },
                {
                  "wildcard": {
                    "keywords.keyword": `${p}`
                  }
                }
              ],
              "must_not": [
                {
                  "match": {
                    "location.country.name": "india"
                  }
                }
              ]
            }
          },
          "weight": 20
        },
        / *********registered foreign user partial match******** /
        {
          "filter": {
            "bool": {
              "must": [
                {
                  "exists": {
                    "field": "userId"
                  }
                },
                {
                  "exists": {
                    "field": "location.country"
                  }
                },
                {
                  "wildcard": {
                    "keywords.keyword": `*${p}*`
                  }
                }
              ],
              "must_not": [
                {
                  "match": {
                    "location.country.name": "india"
                  }
                }
              ]
            }
          },
          "weight": 25
        },

        / *********not registered india user exact match******** /
        {
          "filter": {
            "bool": {
              "must": [
                // {
                // "exists": {
                // "field": "location.country"
                // }
                // },
                {
                  "match": {
                    "location.country.name": "india"
                  }
                },
                {
                  "wildcard": {
                    "keywords.keyword": `${p}`
                  }
                }
              ]
            }
          },
          "weight": 45
        },
        / *********not registered india user partial match******** /
        {
          "filter": {
            "bool": {
              "must": [
                // {
                // "exists": {
                // "field": "location.country"
                // }
                // },
                {
                  "match": {
                    "location.country.name": "india"
                  }
                },
                {
                  "wildcard": {
                    "keywords.keyword": `*${p}*`
                  }
                }
              ]
            }
          },
          "weight": 50
        },
        
        *********not registered foreign user exact match******** /
        {
          "filter": {
            "bool": {
              "must": [
                {
                  "wildcard": {
                    "keywords.keyword": `${p}`
                  }
                }
              ],
              "must_not": [
                {
                  "match": {
                    "location.country.name": "india"
                  }
                }
              ]
            }
          },
          "weight": 55
        },
       / *********not registered foreign user partial match******** /
        {
          "filter": {
            "bool": {
              "must": [
                {
                  "wildcard": {
                    "keywords.keyword": `*${p}*`
                  }
                }
              ],
              "must_not": [
               {
                  "match": {
                    "location.country.name": "india"
                  }
                }
              ]
            }
          },
          "weight": 60
        }
    ]

```

---

<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:** [August 28, 2021, 6:10am UTC](https://discuss.elastic.co/t/delay-in-response-after-using-function-score-for-sorting-of-documents-according-to-field-match/280113/2 "2021-08-28T06:10:40Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
