如何做多个“匹配”或“match_phrase” ElasticSearch中的值 [英] How to do multiple "match" or "match_phrase" values in ElasticSearch
问题描述
所以ElasticSearch具有条款查询,这样我可以提供多个值,并返回一个文档的区域,其中字段X匹配任何这些值。
但是我想用 match_phrase 做同样的事情 - 即返回文档,其中字段X包含带空格的术语的不区分大小写的匹配项。我现在做我使用或过滤器(见下文)。但是,这似乎是一个非常冗长的方式来做我想做的事情,考虑到这些术语已经类似。
当前方法
对于三个值中的一个,搜索单个字段的查询应该是33行长,似乎是可笑的。
{
查询:{
过滤:{
过滤器:{
或:{
:[
{
查询:{
match_phrase:{
myField1:我的第一个搜索短语
}
}
},
{
查询:{
match_phrase:{
myField1:我的第二个搜索短语
}
}
},
{
query:{
match_phrase:{
myField1:我的第三个搜索短语
}
}
}
]
}
}
}
}
}
查询字符串在这些行上将有所帮助
{
pre>
query:{
query_string:{
default_field:myField1,
query:\我的第一个搜索短语 \我的第二个搜索短语\OR \我的第三个搜索短语\\
}
}
}
So ElasticSearch has the terms query, which lets me supply multiple values and return a ist of documents where field X matches any of those values.
But I want to do the same thing with match_phrase - i.e. return documents where field X contains a case insensitive match for a term with spaces. I currently do it my using an or filter (see below). But that seems like a very verbose way of doing what I want, considering that terms does something similar already.
Current method
It seems ridiculous that a query searching a single field for one of three values should be 33 lines long.
{ "query": { "filtered": { "filter": { "or": { "filters": [ { "query": { "match_phrase": { "myField1": "My first search phrase" } } }, { "query": { "match_phrase": { "myField1": "My second search phrase" } } }, { "query": { "match_phrase": { "myField1": "My third search phrase" } } } ] } } } } }
解决方案Query string would be helpful here something on these lines
{ "query": { "query_string": { "default_field": "myField1", "query": "\"My first search phrase\" OR \"My second search phrase\" OR \"My third search phrase\"" } } }
这篇关于如何做多个“匹配”或“match_phrase” ElasticSearch中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!