elasticsearch - 一些属性无法在Elasticsearch 7.4上进行过滤。如何过滤它们?

标签 elasticsearch

我正在使用ElasticSearch 7.4,并且是Elasticsearch的新手

{
  "query": {
    "bool": {
      "must": [
        { "match": { "endpoint.OptOut": "NONE" }}
      ]
    }
  }
}

如果我使用上面的搜索,它将返回此
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 10,
    "successful" : 10,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.2876821,
    "hits" : [
      {
        "_index" : "pinpoint-2020-05-18",
        "_type" : "_doc",
        "_id" : "49607119956414053843418396197478865586643200066386395138.0",
        "_score" : 0.2876821,
        "_source" : {
          "event_type" : "event.click",
          "event_timestamp" : 1589814810000,
          "arrival_timestamp" : 1589814810554,
          "event_version" : "3.1",
          "application" : {
            "app_id" : "c6504a2cca654c0f8415184859857fdc",
            "cognito_identity_pool_id" : "",
            "sdk" : { },
            "version_code" : "11111111"
          },
          "client" : {
            "client_id" : "email-a",
            "cognito_id" : ""
          },
          "device" : {
            "platform" : { }
          },
          "session" : { },
          "endpoint" : {
            "ChannelType" : "EMAIL",
            "Address" : "=ABAQ8rfmFOeZTLCgRSb7iCsfN2uov27mPh1qz9tvksP57O1D6M9u0AaUDdmXjU1/6n+D1n5acqejpSf55a0Uq07AgrSZaE/5RfT90PHtui1J3Jc=",
            "EndpointStatus" : "ACTIVE",
            "OptOut" : "NONE",
            "EffectiveDate" : "2020-05-18T13:34:47.527Z",
            "ApplicationId" : "c6504a2cca654c0f8415184859857fdc",
            "Id" : "email-a",
            "CohortId" : "35",
            "CreationDate" : "2020-05-18T13:34:47.527Z"
          },
          "awsAccountId" : "123456123456"
        }
      }
    ]
  }
}

因此,您可以在endpoint.OptOut字段中看到“NONE”。

但是当我使用下面的json搜索时,
{
  "query": {
    "bool": {
      "filter": [
        {"term": {"endpoint.OptOut": "NONE"}}
      ]
    }
  }
}

它什么也没返回...
它只返回下面
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 10,
    "successful" : 10,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}

我不知道为什么'endpoint.OptOut'无法被过滤。
可以过滤某些属性,例如application.app_id,endpoint.EffectiveDate等。
但是某些属性无法过滤,例如“client.client_id”,“endpoint.OptOut”等。

这是我的映射。
{
  "pinpoint-2020-05-18" : {
    "mappings" : {
      "properties" : {
        "application" : {
          "properties" : {
            "app_id" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "cognito_identity_pool_id" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "sdk" : {
              "type" : "object"
            },
            "version_code" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "arrival_timestamp" : {
          "type" : "date",
          "format" : "epoch_millis"
        },
        "attributes" : {
          "properties" : {
            "campaign_activity_id" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "campaign_id" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "campaign_send_status" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "campaign_send_status_code" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "campaign_send_status_message" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "feedback" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "treatment_id" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "awsAccountId" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "client" : {
          "properties" : {
            "client_id" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "cognito_id" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "client_context" : {
          "properties" : {
            "custom" : {
              "properties" : {
                "endpoint" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                },
                "legacy_identifier" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            }
          }
        },
        "device" : {
          "properties" : {
            "platform" : {
              "type" : "object"
            }
          }
        },
        "endpoint" : {
          "properties" : {
            "Address" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "ApplicationId" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "ChannelType" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "CohortId" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "CreationDate" : {
              "type" : "date"
            },
            "EffectiveDate" : {
              "type" : "date"
            },
            "EndpointStatus" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "Id" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "OptOut" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "event_timestamp" : {
          "type" : "long"
        },
        "event_type" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "event_version" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "facets" : {
          "properties" : {
            "email_channel" : {
              "properties" : {
                "mail_event" : {
                  "properties" : {
                    "delivery" : {
                      "properties" : {
                        "processing_time_millis" : {
                          "type" : "long"
                        },
                        "recipients" : {
                          "type" : "text",
                          "fields" : {
                            "keyword" : {
                              "type" : "keyword",
                              "ignore_above" : 256
                            }
                          }
                        },
                        "reporting_mta" : {
                          "type" : "text",
                          "fields" : {
                            "keyword" : {
                              "type" : "keyword",
                              "ignore_above" : 256
                            }
                          }
                        },
                        "smtp_response" : {
                          "type" : "text",
                          "fields" : {
                            "keyword" : {
                              "type" : "keyword",
                              "ignore_above" : 256
                            }
                          }
                        }
                      }
                    },
                    "mail" : {
                      "properties" : {
                        "common_headers" : {
                          "properties" : {
                            "date" : {
                              "type" : "text",
                              "fields" : {
                                "keyword" : {
                                  "type" : "keyword",
                                  "ignore_above" : 256
                                }
                              }
                            },
                            "from" : {
                              "type" : "text",
                              "fields" : {
                                "keyword" : {
                                  "type" : "keyword",
                                  "ignore_above" : 256
                                }
                              }
                            },
                            "subject" : {
                              "type" : "text",
                              "fields" : {
                                "keyword" : {
                                  "type" : "keyword",
                                  "ignore_above" : 256
                                }
                              }
                            },
                            "to" : {
                              "type" : "text",
                              "fields" : {
                                "keyword" : {
                                  "type" : "keyword",
                                  "ignore_above" : 256
                                }
                              }
                            }
                          }
                        },
                        "destination" : {
                          "type" : "text",
                          "fields" : {
                            "keyword" : {
                              "type" : "keyword",
                              "ignore_above" : 256
                            }
                          }
                        },
                        "from_address" : {
                          "type" : "text",
                          "fields" : {
                            "keyword" : {
                              "type" : "keyword",
                              "ignore_above" : 256
                            }
                          }
                        },
                        "headers" : {
                          "properties" : {
                            "name" : {
                              "type" : "text",
                              "fields" : {
                                "keyword" : {
                                  "type" : "keyword",
                                  "ignore_above" : 256
                                }
                              }
                            },
                            "value" : {
                              "type" : "text",
                              "fields" : {
                                "keyword" : {
                                  "type" : "keyword",
                                  "ignore_above" : 256
                                }
                              }
                            }
                          }
                        },
                        "headers_truncated" : {
                          "type" : "boolean"
                        },
                        "message_id" : {
                          "type" : "text",
                          "fields" : {
                            "keyword" : {
                              "type" : "keyword",
                              "ignore_above" : 256
                            }
                          }
                        },
                        "message_send_timestamp" : {
                          "type" : "long"
                        }
                      }
                    },
                    "open" : {
                      "properties" : {
                        "ip_address" : {
                          "type" : "text",
                          "fields" : {
                            "keyword" : {
                              "type" : "keyword",
                              "ignore_above" : 256
                            }
                          }
                        },
                        "user_agent" : {
                          "type" : "text",
                          "fields" : {
                            "keyword" : {
                              "type" : "keyword",
                              "ignore_above" : 256
                            }
                          }
                        }
                      }
                    },
                    "send" : {
                      "type" : "object"
                    }
                  }
                }
              }
            }
          }
        },
        "session" : {
          "type" : "object"
        }
      }
    }
  }
}

请让我知道,为什么某些属性无法过滤。
以及如何过滤

谢谢!

最佳答案

这里有两件事。

  • bool.filterbool.must相同,不同之处在于评分is not affected。因此,错误不是由于filter而是因为点2。
  • term用于精确匹配。由于您的OptOut字段已应用(我假设)默认的standard analyzer,因此在幕后将其小写,这就是为什么您看不到任何匹配项的原因。幸运的是,ES也生成了keyword字段,因此您可以执行
  • {
      "query": {
        "bool": {
          "filter": [
            {"term": {"endpoint.OptOut.keyword": "NONE"}}
          ]
        }
      }
    }
    

    应该返回结果。

    请注意,以上内容需要精确区分大小写的关键字进行过滤。

    关于elasticsearch - 一些属性无法在Elasticsearch 7.4上进行过滤。如何过滤它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61890643/

    相关文章:

    elasticsearch - 如何通过索引名称(通配符)搜索Elasticsearch索引列表

    elasticsearch - 流利的位 : Logstash_Prefix_Key is not working as expected with 'es' output plugin

    macos - 让 SonarQube 在 MacOS 中工作时出现问题

    elasticsearch - 无法为 Kibana 安装 sense 插件

    amazon-web-services - AWS Elasticsearch集群方法更新 `http.max_content_length`?

    elasticsearch - 是否可以在Elasticsearch的批量api中使用按查询删除插件?

    elasticsearch - ElasticSearch:按词条查找项目,如果不存在则将其忽略

    elasticsearch - Elasticsearch 总和聚合中的问题

    elasticsearch - 如何跟踪被拒绝和丢弃事件的总数

    php - 如何使用 PHP 中的访问 key 连接到 AWS Elasticsearch 服务?