elasticsearch 多匹配搜索查询子句限制

lawou6xi  于 7个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(83)

我使用的是多匹配查询,如下所示的字段和查询。(ElasticSearch7.0)

GET users_index/_search
{
  "query": {
    "multi_match": {
      "query": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19",
      "fields": ["users.id",  "users.org", "users.email", "users.name", "posts.id"], 
      "operator": "and"
    }
  },
  "size": 25, 
  "sort": [
    {
      "posts.id": {
        "order": "desc"
      }
    }
  ]
}

字符串
有时当我的查询有更多的术语时,即使19*5 < 1024,我也会得到Query contains too many nested clauses; maxClauseCount is set to 1024错误。在计算限制时是否有其他子句起作用。这是因为ngram吗?
索引设置

"users": {
  "properties": {
    "organization": {
      "type": "text",
      "norms": false,
      "analyzer": "custom_analyzer"
    },
    "email": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword"
        }
      },
      "norms": false,
      "analyzer": "custom_analyzer"
    },
    "id": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword"
        }
      },
      "norms": false,
      "analyzer": "custom_analyzer"
    },
    "name": {
      "type": "text",
      "norms": false,
      "analyzer": "custom_analyzer"
    }
  }
}
"analysis": {
  "analyzer": {
    "custom_analyzer": {
      "filter": [
        "lowercase"
      ],
      "type": "custom",
      "tokenizer": "ngram_tokenizer"
    }
  },
  "tokenizer": {
    "ngram_tokenizer": {
      "type": "ngram",
      "min_gram": "3",
      "max_gram": "7"
    }
  }
}

hzbexzde

hzbexzde1#

您的多匹配查询是问题所在。5个字段中的19个术语已经产生了95个子句,根据文本字段的分析设置,这可能会进一步增加。
你可以使用它来改进:

> "bool": {
>     "should": [
>       {"match": {"users.id": "1"}},
>       {"match": {"users.org": "1"}},
>       ...
>     ],
>     "minimum_should_match": 19   }

字符串
或者,如果你的服务器足够大,你可以从弹性配置中增加maxClauseCount

相关问题