- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个相当大的terms
聚合结果,这些结果被加载到下拉列表中以提供filter
功能。
可以说,我的下拉列表中有4000多种动物。我的另一个下拉列表有4种动物颜色。
例,animal --> ["dog", "cat", "rabbit", ........ , "squirrel"]
color --> ["black", "white", "grey", "brown"]
elasticseatch
中的文档如下所示:
{"animal": "dog", "color": "white"},
....
{"animal": "cat", "color": "white"},
....
{"animal": "rabbit", "color": "grey"},
....
{"animal": "squirrel", "color": "brown"}
checkboxes
都是
checked
,Elasticsearch返回它包含的所有结果。现在,我想查看基于所选动物颜色的另一个字段
animal_features
的基数结果。如果下拉列表中没有
checked
,那么实际上可以轻松完成此操作,而我可以运行以下查询。当color = black时,查询将返回预期的基数结果。
{
"query": {
"bool": {
"must": [
{"match": { "color": "black"}}
]
}
},
"aggs": {
"unique_animal_features": {
"cardinality": {
"field": "animal_features",
"precision_threshold" : 40000
}
}
}
}
checked
。假设我仍然需要color = black时的基数结果。因此,就我而言,我需要取消选中除黑色之外的所有其他颜色。因此,我继续取消选中白色,灰色和棕色。
must_not
查询从结果中排除了不是黑色的其他颜色。
{
"query": {
"bool": {
"must_not": [
{
"match": {
"color": "white"
}
},
{
"match": {
"color": "grey"
}
},
{
"match": {
"color": "brown"
}
}
]
}
},
"aggs": {
"unique_animal_features": {
"cardinality": {
"field": "animal_features",
"precision_threshold" : 40000
}
}
}
]
}
最佳答案
我能够找出问题所在。在我的情况下,elasticsearch中有null
值,第二个查询返回基于所选animal
和包含null
的记录的基数计数。
我将"null_value": "_null_"
添加到索引模板中,并通过以下查询获得正确的值。
{
"query": {
"bool": {
"must_not": [
{
"match": {
"color": "_null_"
}
},
{
"match": {
"color": "white"
}
},
{
"match": {
"color": "grey"
}
},
{
"match": {
"color": "brown"
}
}
]
}
},
"aggs": {
"unique_animal_features": {
"cardinality": {
"field": "animal_features",
"precision_threshold" : 40000
}
}
}
]
}
关于elasticsearch - elasticsearch必须与MUST_NOT(反)差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46284520/
我正在尝试滤除Kibana中的错误,但不是所有错误,而是仅在消息字段中没有特定字符串的错误。我的查询如下: GET search-apps/_search { "query": { "bo
对于我的项目之一,我需要从ES索引确定缺少字段的所有记录。 请在下面查看存储在我的ES索引中的数据示例: { "schema": "https://sample.org/schemas/user_
我想过滤掉 LogMessage 字段中存在 Too many connections 的所有文档。 我写的查询是: ' { "query": { "bool": { "mus
我正在从事医疗项目,我有多个问题及其附带的主题。问题是以下代码工作正常,但它没有考虑“must_not”过滤器,而使用“must”子句则工作正常。帮我解决这个问题。 GET stopdata/_sea
给定一个包含此文本的文档,索引在名为 Content 的字段中: The dish ran away with the spoon. 以下查询无法匹配该文档: +Content:dish +(-Con
我们运行大量的文章数据集。我们根据某些关键字,过滤器,范围等进行搜索。我们的查询包含MUST/SHOULD/MUST_NOT/FILTER结构。 我们需要能够强制某些结果显示与MUST_NOT条件匹配
根据文档 must_not The clause (query) must not appear in the matching documents. 我有这样的查询: // searching fo
我有一个查询,我想在其中添加一个 must_not 子句,该子句将丢弃在某些字段中具有空白数据的所有记录。我尝试了很多方法,但都没有用。当我对其他特定字段发出相同的查询(如下所述)时,它工作正常。 此
我目前正在努力处理 ElastSearch 查询,该查询目前看起来如下: ... "query": { "bool": { "must_not": [
我的 elasticsearch 数据库中有一个看起来像这样的文档: { "tags" => [ "tag-1", "tag-2", "tag-3",
我有一个如下所示的ES索引: "_source" : { "text_terms" : [ { "term" : "aaa",
我有以下情况: 我们目前通过商业解决方案实现了产品搜索。 我正在使用 Elasticsearch 来实现我们当前使用 Elasticsearch 进行的产品搜索,基本上效果很好。 但我们有一个专长。我
我是 ElasticSearch 的新手,目前正在研究“must”和“must_not”类型的搜索条件。我有以下查询 DSL: curl -XPOST 'localhost:9200/employee
为什么must_not在“过滤器”中不起作用? (请看下面的图片)。 相同的“must_not”适用于“query”(图片中的注释) 以文字查询: GET _search { "query": {
查询示例- GET /beta/user/_search?routing=1&q=_id:54e5dc4817cf03cbbbe490e5 { "from":0, "size":1
我想知道使用 must 子句和 must_not 之间的性能差异。我从他们两个那里得到不同的时间尝试。假设我有 10 个组,我想让用户访问 5 个组,同时排除 5 个组。因此,我有两种使用查询的方法:
具有以下映射: "categories": { "type": "nested", "properties": { "category": { "type":
我在组合 term, must_not 嵌套文档查询时遇到问题。 意义示例可以在这里找到:http://sense.qbox.io/gist/be436a1ffa01e4630a964f48b2d5b
我在 Windows 8 计算机上使用elasticsearch-py 7.0 和elasticsearch server 7.0。 我有这个查询: { 'size': 10000,
我想将 ids 查询与 must_not 子句结合起来。我在 Rails 应用程序中使用(重新)轮胎 gem。 我正在做这样的事情: query do ids ["foo", "bar", "te
我是一名优秀的程序员,十分优秀!