有偿,有偿,寻求大佬优化查询

查询一次时间,大约 30 秒。 elasticsearch 8.15,单机,总数据量大约 200 万,filter 过滤后大约 1 万~20 万

部分索引如下

"mappings": {
        "properties": {
            "brandId": {
                "type": "long"
            },
            "pageContent": {
                "analyzer": "store_analyzer_page",
                "search_analyzer": "search_analyzer_page",
                "type": "text"
            },
            "pageEmbedding": {
              "type": "dense_vector",
              "dims": 1024,
              "index": true,
              "similarity": "cosine",
              "index_options": {
                "type": "int8_hnsw",
                "m": 16,
                "ef_construction": 100
              }
            }
        }
    }

部分查询语句如下,

{
  "knn": [
    {
      "field": "pageEmbedding",
      "query_vector": {{embedding}},
      "k": 200,
      "num_candidates": 1000,
      "boost": 1.0,
      "filter": [
        {
          "bool": {
            "filter": [
              {
                "term": {
                  "brandId": {
                    "value": {{brandId}}
                  }
                }
              }
            ]
          }
        }
      ]
    }
  ],
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "brandId": {
              "value": {{brandId}}
            }
          }
        },
      ],
      "should": [
        {
          "match": {
            "pageContent": {
              "boost": 0.5,
              "query": "{{keyword}}"
            }
          }
        }
      ]
    }
  },
}

部分查询条件会 400ms 左右返回,偶尔会出现查询出现 30 秒,应该如何优化?

来源:https://v2ex.com/t/1170162