How To optimize Elastic Search Query and mapping to fetch the result quickly

I have the following index mapping and Elastic search query,

Sample Index Mapping:-

{
  "college_metric": {
    "mappings": {
      "properties": {
        "Batch__kt": {
          "type": "nested",
          "include_in_root": true,
          "properties": {
            "course": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "keyword"
                }
              }
            },
            "stream": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "keyword"
                }
              }
            }
          }
        },
        "batch_type": {
          "type": "text",
          "fields": {
            "raw": {
              "type": "keyword"
            }
          }
        },
        "batch_title": {
          "type": "text",
          "fields": {
            "raw": {
              "type": "keyword"
            }
          }
        },
        "effective_date": {
          "type": "keyword",
          "fields": {
            "raw": {
              "type": "date",
              "format": "date_optional_time"
            }
          }
        },
        "batch_number": {
          "type": "keyword",
          "fields": {
            "raw": {
              "type": "integer"
            }
          }
        },
        "Management__kt": {
          "type": "nested",
          "include_in_root": true,
          "properties": {
            "Pricing": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "keyword"
                }
              }
            },
            "Operation": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "integer"
                }
              }
            },
            "Maintaince": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "keyword"
                }
              }
            },
            "Symetric": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "keyword"
                }
              }
            },
            "Owner": {
              "type": "text",
              "fields": {
                "raw": {
                  "type": "keyword"
                }
              }
            }
          }
          ...
        }
      }
    }
  }
}

Elastic Search Query:-

GET college_metric/_search
{
  "from": 0,
  "size": 10,
  "_source": [
    "batch_title",
    "batch_number",
    "batch_type",
    "effective_date"
  ],
  "track_total_hits": true,
  "query": {
    "function_score": {
      "query": {
        "bool": {
          "filter": {
            "bool": {
              "must": [
                {
                  "term": {
                    "type": "colleges"
                  }
                }
              ],
            }
          },
          "should": [
            {
              "query_string": {
                "query": "account",
                "type": "best_fields",
                "fields": [
                  "batch_title",
                  "batch_number",
                  "batch_type",
                  "*__kt.*"
                ],
                "lenient": true,
                "default_operator": "AND",
                "boost": 3
              }
            },
            {
              "query_string": {
                "query": "account",
                "type": "phrase_prefix",
                "fields": [
                  "batch_title",
                  "batch_number",
                  "batch_type",
                  "effective_date"
                  "*__kt.*"
                ],
                "lenient": true,
                "boost": 2
              }
            },
            {
              "query_string": {
                "query": "account",
                "fields": [
                  "batch_title",
                  "batch_number",
                  "batch_type",
                  "effective_date"
                  "*__kt.*"
                ],
                "lenient": true,
                "type": "best_fields"
              }
            }
          ],
          "minimum_should_match": 1
        }
      }
    }
  },
  "min_score": 0.000001,
  "highlight": {
    "fields": {
      "*": {
        "type": "plain"
      }
    }
  }
} 

Is there any way to optimize this mapping or maybe the Query so that we can fetch the result quickly, This query is taking more time to bring the outcome for some keywords like "account". and when I am searching for more results for the same keyword after increasing the size value from 10 to 40-50 then Elastic Search Kibana itself throws a 504 Gateway Time-out Error.

Note:- 7.10 elastic-search version I am using.

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