gpt4 book ai didi

禁用对象中的 ElasticSearch 查询字段

转载 作者:行者123 更新时间:2023-12-02 22:13:03 25 4
gpt4 key购买 nike

我有一个 Elastic Search 6.8.7 集群。

我有一个带有此映射的列:

"event_object": { "enabled": false, "type": "object" }

我想搜索与某些其他条件匹配的记录,并且还具有此对象中特定字段字段的特定值。

到目前为止,我已经尝试了对索引字段进行正常搜索的变体,以及对未索引字段的过滤脚本:
GET /my_index/_search
{
"query":{
"bool":{
"must":{
"query_string": {
"query": "foo:bar"
}
},
"filter": {
"script": {
"script": {
"source": "doc[\"event_object\"][\"state\"].value == \"R\""
}
}
}
}
},
"terminate_after":1000,
"from":0,
"size":1000
}

这是基于谷歌搜索测试自己的大杂烩。但是我什至无法编译,更不用说运行和过滤了。

最佳答案

无法访问具有 enabled: false 的 JSON 对象的内容.来自 official documentation :

Elasticsearch skips parsing of the contents of the field entirely. The JSON can still be retrieved from the _source field, but it is not searchable or stored in any other way



因此,即使是脚本编写也无济于事。

但是,有一种方法可以通过 terms 中的脚本访问这些禁用的数据。聚合(使用 include 参数和 top_hits 子聚合):
POST test/_search
{
"query": {
"match_all": {}
},
"aggs": {
"state": {
"terms": {
"script": "params._source.event_object.state",
"size": 100,
"include": "R"
},
"aggs": {
"hits": {
"top_hits": {
"size": 10
}
}
}
}
}
}

你会得到这样的回应:
  "aggregations" : {
"state" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "R",
"doc_count" : 1,
"hits" : {
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"event_object" : {
"state" : "R"
},
"test" : "hello"
}
}
]
}
}
}
]
}
}

关于禁用对象中的 ElasticSearch 查询字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61909589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com