首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >弹性搜索-不一致项的结果

弹性搜索-不一致项的结果
EN

Stack Overflow用户
提问于 2014-07-30 14:34:08
回答 1查看 652关注 0票数 0

我在以前的帖子中找不到答案,所以我希望我的帖子是相关的。我遇到了ElasticSearch术语方面的问题。

当我查询每个术语方面的文档计数时,我得到,比方说,8表示某个字段值,但是当我用该字段的特定值查询文档计数时,我得到,例如19。

更简单地说,我正在使用Kibana,下面是查询和响应(告诉我要重命名字段值fyi):

所有术语方面计数查询:

代码语言:javascript
复制
{
    "facets" : {
        "terms" : {
            "terms" : {
                **"fields" : ["field.name"],**
                "size" : 6,
                "order" : "count",
                "exclude" : []
            },
            "facet_filter" : {
                "fquery" : {
                    "query" : {
                        "filtered" : {
                            "query" : {
                                "bool" : {
                                    "should" : [{
                                            "query_string" : {
                                                "query" : "*"
                                            }
                                        }
                                    ]
                                }
                            },
                            "filter" : {
                                "bool" : {
                                    "must" : [{
                                            "match_all" : {}

                                        }
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "size" : 0
}

响应:

代码语言:javascript
复制
{
    "took" : 1,
    "timed_out" : false,
    "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
    },
    "hits" : {
        "total" : 20374,
        "max_score" : 0.0,
        "hits" : []
    },
    "facets" : {
        "terms" : {
            "_type" : "terms",
            "missing" : 10567,
            "total" : 9918,
            "other" : 9781,
            "terms" : [{
                    "term" : "fieldValue1"
                    "count" : 43
                }, {
                    "term" : "fieldValue2",
                    "count" : 27
                }, {
                    "term" : "fieldValue3",
                    "count" : 23
                }, {
                    "term" : "fieldValue4",
                    "count" : 23
                }, {
                    "term" : "fieldValue5",
                    "count" : 13
                }, {
                    "term" : "fieldValue6",
                    "count" : 8
                }
            ]
        }
    }
}

对"fieldValue6"的查询

代码语言:javascript
复制
{
    "facets" : {
        "terms" : {
            "terms" : {
                "fields" : ["field.name"],
                "size" : 6,
                "order" : "count",
                "exclude" : []
            },
            "facet_filter" : {
                "fquery" : {
                    "query" : {
                        "filtered" : {
                            "query" : {
                                "bool" : {
                                    "should" : [{
                                            "query_string" : {
                                                "query" : "*"
                                            }
                                        }
                                    ]
                                }
                            },
                            "filter" : {
                                "bool" : {
                                    "must" : [{
                                            "terms" : {
                                                "field.name" : ["fieldValue6"]
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "size" 

响应:

代码语言:javascript
复制
{
    "took" : 2,
    "timed_out" : false,
    "_shards" : {
        "total" : 5,
        "successful" : 5,
        "failed" : 0
    },
    "hits" : {
        "total" : 20374,
        "max_score" : 0.0,
        "hits" : []
    },
    "facets" : {
        "terms" : {
            "_type" : "terms",
            "missing" : 0,
            "total" : 19,
            "other" : 0,
            "terms" : [{
                    "term" : "fieldValue6",
                    "count" : 19
                }
            ]
        }
    }
}

我应用facet过滤器的字段(或者它实际上应该被调用的任何内容)被设置为“”:

代码语言:javascript
复制
properties: {
    type_ref2Strack: {
        properties: {
            position: {
                type: long
            }
            name: {
                index: not_analyzed
                norms: {
                    enabled: false
                }
                index_options: docs
                type: string
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-31 03:27:50

这是众所周知的对elasticsearch方面(现在称为聚合)的长期限制。

关键的问题是,它对给定大小的每个碎片运行面,然后组合结果,这意味着计数可以被砍掉。

有两种非理想的方法来处理这个问题:

  • 添加比实际需要大得多的"shard_size“输入。这主要是可行的,但计数仍然不能保证是准确的。
  • 有一个仅仅是一个碎片的索引。这样,它总是收集准确的结果。这将影响将索引缩放到非常多的文档,但是YMMV

有关更多信息,请参见此处:

approximate

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25039579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档