在弹性搜索中找到空字符串 [英] Find empty strings in elasticsearch
问题描述
我正在尝试在该字段中具有某些特定价值的 _search
文档。
{
query:{
bool:{
must:[
{field:{advs.status warn}}
]
}
}
}
这个工作找到。但是当我试图找到那个字段中有空字符串的文档时,我得到这个错误:
ParseException [无法解析''...
然后 - 预期的长列表,而不是空字符串。 p>
我尝试这个查询:
{
query :{
bool:{
must:[
{term:{advs.status:}}
]
}
}
}
它没有失败但没有发现。它适用于非空字符串。我应该怎么做?
我的这种类型的映射看起来像这样:
{
reports:{
dynamic:false,
_ttl:{
enabled:true,
default:7776000000
},
properties:{
@fields:{
dynamic:true,
:{
upstream_status:{
type:string
}
}
},
advs:{
property:{
status:{
type:string,
store:yes
}
}
},
advs.status:{
type:string,
store:yes
}
}
}
}
或另一种方法使用存在
过滤器:
存在:{
field:advs.status
}
两个都是有效的,但这一个更好:)
I'm trying to _search
documents that has some specific value in the field.
{
"query": {
"bool": {
"must": [
{"field": {"advs.status": "warn"}}
]
}
}
}
That works find. But when I'm trying to find documents that has empty string in that field, I get this error:
ParseException[Cannot parse '' ...
and then - long list of what was expected instead of empty string.
I try this query:
{
"query": {
"bool": {
"must": [
{"term": {"advs.status": ""}}
]
}
}
}
It doesn't fails but finds nothing. It works for non empty strings instead. How am I supposed to do this?
My mapping for this type looks exactly like this:
{
"reports": {
"dynamic": "false",
"_ttl": {
"enabled": true,
"default": 7776000000
},
"properties": {
"@fields": {
"dynamic": "true",
"properties": {
"upstream_status": {
"type": "string"
}
}
},
"advs": {
"properties": {
"status": {
"type": "string",
"store": "yes"
}
}
},
"advs.status": {
"type": "string",
"store": "yes"
}
}
}
}
Or another way to do the same thing more efficiently is to use the exists
filter:
"exists" : {
"field" : "advs.status"
}
Both are valid, but this one is better :)
这篇关于在弹性搜索中找到空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!