ElasticSearch如何获取其中包含10个或更多字段的文档? [英] ElasticSearch how to get docs with 10 or more fields in them?
本文介绍了ElasticSearch如何获取其中包含10个或更多字段的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想获取所有包含10个或更多字段的文档。我猜是这样的:
I want to get all docs that have 10 or more fields in them. I'm guessing something like this:
{
"query": {
"range": {
"fields": {
"gt": 1000
}
}
}
}
推荐答案
您可以做的就是运行这样的脚本查询
What you can do is to run a script query like this
{
"query": {
"script": {
"script": {
"source": "params._source.size() >= 10"
}
}
}
}
但是,请注意,取决于您拥有的文档数量和支持集群的硬件,这可能会对集群的性能产生负面影响。
However, be advised that depending on the number of documents you have and the hardware that supports your cluster, this can negatively impact the performance of your cluster.
一个更好的主意是添加另一个包含文档包含的字段数的整数字段,因此您可以简单地运行 range
查询就像您的问题一样。
A better idea would be to add another integer field that contains the number of fields that the document contains, so you can simply run a range
query on it, like in your question.
这篇关于ElasticSearch如何获取其中包含10个或更多字段的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文