弹性搜索匹配列表 [英] Elasticsearch match list against field
问题描述
[John,Bas,Peter]
,我想查询名称
它匹配其中一个名称。 一种方法是使用OR Filter。例如
{
filtered:{
query:{
match_all :{}
},
过滤器:{
或:[
{
term:{name:John}
},
{
term:{name:Bas}
},
{
term:{name :彼得}
}
]
}
}
}
任何鸽友的方式?
{
查询:{
filtered:{
filter:{
terms:{
name:[John,Bas,Peter ]
}
}
}
}
}
哪个弹性搜索重写,就好像你使用这个帽子一样
{
query:{
filtered:{
filter:{
bool:{
should:[
{
term:{
name:John
}
},
{
term:{
name:Bas
}
},
{
term:{
name:Peter
}
}
]
}
}
}
}
}
当使用布尔过滤器时,大多数情况下,使用 bool
过滤器比和
或或
。原因在Elasticsearch博客中解释: http://www.elasticsearch.org/blog/ all-about-elasticsearch-filter-bitsets /
I have a list, array or whichever language you are familiar. E.g. names : ["John","Bas","Peter"]
and I want to query the name
field if it matches one of those names.
One way is with OR Filter. e.g.
{
"filtered" : {
"query" : {
"match_all": {}
},
"filter" : {
"or" : [
{
"term" : { "name" : "John" }
},
{
"term" : { "name" : "Bas" }
},
{
"term" : { "name" : "Peter" }
}
]
}
}
}
Any fancier way? Better if it's a query than a filter.
{
"query": {
"filtered" : {
"filter" : {
"terms": {
"name": ["John","Bas","Peter"]
}
}
}
}
}
Which Elasticsearch rewrites as if you hat used this one
{
"query": {
"filtered" : {
"filter" : {
"bool": {
"should": [
{
"term": {
"name": "John"
}
},
{
"term": {
"name": "Bas"
}
},
{
"term": {
"name": "Peter"
}
}
]
}
}
}
}
}
When using a boolean filter, most of the time, it is better to use the bool
filter than and
or or
. The reason is explained on the Elasticsearch blog: http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/
这篇关于弹性搜索匹配列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!