[英]Add simple search on every field in ElasticSearch
here's my query:这是我的查询:
"query":{
"query":{
"bool":{
"must":[
{
"term":{
"device_id":"1"
}
},
{
"range":{
"created_at":{
"gte":"2019-10-01",
"lte":"2019-12-10"
}
}
}
],
"must_not":[
{
"term":{
"action":"ping"
}
},
{
"term":{
"action":"checkstatus"
}
}
]
}
},
"sort":{
"created_at":"desc"
},
"size":10,
"from":0
}
the logs vary a lot with completely different set of fields.日志差异很大,具有完全不同的字段集。 What I can do to search if in any of them is a string that I'm looking for?我可以做些什么来搜索其中任何一个是我正在寻找的字符串? Let's say I'm looking for "mit" and it shows me one log with假设我正在寻找“mit”,它向我显示了一个日志
surname -> Smith姓氏 -> 史密斯
and the second one with第二个是
action -> "message comMITted"动作->“已提交消息”
I've tried using match [ '_all' => "mit" ] but it's deprecated I heard.我试过使用 match [ '_all' => "mit" ] 但我听说它已被弃用。
I'm using Elasticsearch 7.3.1我正在使用 Elasticsearch 7.3.1
To perform search across all fields, use copy_to to copy the values of all fields into a grouped field, and perform the queries against that field.要跨所有字段执行搜索,请使用copy_to将所有字段的值复制到分组字段中,然后针对该字段执行查询。 In case you have dynamic index mappings refer this .如果您有动态索引映射,请参阅此。
For supporting infix matching, you can use ngrams.为了支持中缀匹配,您可以使用 ngrams。 This is a good tutorial for ngrams. 这是一个很好的 ngrams 教程。
Infix matching can be performed using wildcard query too.也可以使用通配符查询来执行中缀匹配。 But it's not recommended due to performance reasons.但由于性能原因,不建议这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.