elasticsearch elasticsearch“;没有;查询
某些文档具有类别字段。。其中一些文档具有类别字段,其值等于“-1”。我需要一个查询返回文件有类别字段和“不等于-1” 我试过这个:elasticsearch elasticsearch“;没有;查询,elasticsearch,elasticsearch,某些文档具有类别字段。。其中一些文档具有类别字段,其值等于“-1”。我需要一个查询返回文件有类别字段和“不等于-1” 我试过这个: GET webproxylog/_search { "query": { "filtered": { "filter": { "not":{ "filter": {"and": { "filters": [ {"term": {
GET webproxylog/_search
{
"query": {
"filtered": {
"filter": {
"not":{
"filter": {"and": {
"filters": [
{"term": {
"category": "-1"
}
},
{
"missing": {
"field": "category"
}
}
]
}}
}
}
}
}
}
但不是工作。。退货单据没有“类别字段”
编辑
映射:
{
"webproxylog": {
"mappings": {
"accesslog": {
"properties": {
"category": {
"type": "string",
"index": "not_analyzed"
},
"clientip": {
"type": "string",
"index": "not_analyzed"
},
"clientmac": {
"type": "string",
"index": "not_analyzed"
},
"clientname": {
"type": "string",
"index": "not_analyzed"
},
"duration": {
"type": "long"
},
"filetype": {
"type": "string",
"index": "not_analyzed"
},
"hierarchycode": {
"type": "string",
"index": "not_analyzed"
},
"loggingdate": {
"type": "date",
"format": "dateOptionalTime"
},
"reqmethod": {
"type": "string",
"index": "not_analyzed"
},
"respsize": {
"type": "long"
},
"resultcode": {
"type": "string",
"index": "not_analyzed"
},
"url": {
"type": "string",
"analyzer": "slash_analyzer"
},
"user": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
如果您的
类别
字段是字符串
,并在默认情况下进行了分析,则您的-1
将被索引为1
(去掉减号)
您需要对该字段进行未分析
或添加未分析的子字段(如我下面的解决方案)
大概是这样的:
DELETE test
PUT /test
{
"mappings": {
"test": {
"properties": {
"category": {
"type": "string",
"fields": {
"notAnalyzed": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
POST /test/test/1
{"category": "-1"}
POST /test/test/2
{"category": "2"}
POST /test/test/3
{"category": "3"}
POST /test/test/4
{"category": "4"}
POST /test/test/5
{"category2": "-1"}
GET /test/test/_search
{
"query": {
"bool": {
"must_not": [
{
"term": {
"category.notAnalyzed": {
"value": "-1"
}
}
},
{
"filtered": {
"filter": {
"missing": {
"field": "category"
}
}
}
}
]
}
}
}
如果您的类别
字段是字符串
,并在默认情况下进行了分析,则您的-1
将被索引为1
(去掉减号)
您需要对该字段进行未分析
或添加未分析的子字段(如我下面的解决方案)
大概是这样的:
DELETE test
PUT /test
{
"mappings": {
"test": {
"properties": {
"category": {
"type": "string",
"fields": {
"notAnalyzed": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
POST /test/test/1
{"category": "-1"}
POST /test/test/2
{"category": "2"}
POST /test/test/3
{"category": "3"}
POST /test/test/4
{"category": "4"}
POST /test/test/5
{"category2": "-1"}
GET /test/test/_search
{
"query": {
"bool": {
"must_not": [
{
"term": {
"category.notAnalyzed": {
"value": "-1"
}
}
},
{
"filtered": {
"filter": {
"missing": {
"field": "category"
}
}
}
}
]
}
}
}
我将映射更改为未分析(已编辑的问题)。但是查询仍然返回文档没有类别字段映射更改后您是否对文档重新编制了索引?您是否使用我的查询或您的查询进行了测试?是的,对所有查询重新编制了索引,我尝试了两个查询。但不是工作。。你的查询没有返回任何内容我的返回文档没有类别字段我认为你的是真的让我做一个小更改映射到未分析(编辑的问题)。但是查询仍然返回文档没有类别字段映射更改后您是否对文档重新编制了索引?您是否使用我的查询或您的查询进行了测试?是的,对所有查询重新编制了索引,我尝试了两个查询。但不是工作。。你的查询没有返回任何内容我的返回文件没有类别字段我想你的是真的让我等一分钟