elasticsearch - Elasticsearch POST /delete_by_query 不起作用
问题描述
我尝试使用 POST /delete_by_query 删除 Elasticsearch 中的文档,但它在执行时没有删除文档,但没有引发错误。有趣的是它适用于某些索引,但不适用于其他索引。发生这种情况有什么原因吗?
POST /my-index/_delete_by_query?slices=1&requests_per_second=-1&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&ignore_throttled=true&refresh=true&conflicts=proceed&wait_for_completion=true
{
"size": 1000,
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"terms": {
"myAttributeKey1": [
"myAttributeValue1"
],
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
{
"query_string": {
"query": "myAttributeValue2",
"fields": [
"myAttributeKey2"
],
"type": "best_fields",
"default_operator": "and",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"_source": false
}
解决方案
事实证明,索引映射是问题所在。下面是索引映射。我应该使用 termmyAttributeKey1.keyword
而不是myAttributeKey1
可以通过修复索引映射来解决。
{
"mapping": {
"_doc": {
"properties": {
"myAttributeKey1": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
这里作为您可能想要的映射的比较
{
"mapping": {
"_doc": {
"properties": {
"_class": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"myAttributeKey1": {
"type": "keyword"
}
}
}
}
}
推荐阅读
- unit-testing - 我可以将 PBIX 报告中过滤器的值提取到文本文件中进行测试吗?
- python - 将我的代码的所有部分放入优化模型的函数中
- python - Python & Pandas - 将带有标题行的表转换为项目级行
- c++ - 是否可以使用一个父类的方法来实现另一个父类的抽象方法?
- java - Android-如何创建一个新的可写文件?
- azure-active-directory - Dynamics Business 365 Central API 和 Postman
- mysql - Mysql主用户创建不会通过工作台在从属上复制
- javascript - JavaScript React 项目中的高 Jest 堆内存使用率
- sql - T-SQL 字符索引 patindex
- windows - 尽管有效的 SSH 身份验证,但 Git 的权限被拒绝