多个字段上的弹性搜索短语前缀查询 [英] Elasticsearch phrase prefix query on multiple fields
问题描述
我是ES的新手,我正在尝试构建一个可以为多个字段使用phrase_prefix的查询,所以我不必多次搜索。这是我到目前为止已经有的:
{
查询:{
:{
first_name:{
query:Gustavo,
type:phrase_prefix
}
}
}
}'
有人知道如何搜索多个字段,说last_name ?
文本查询已被弃用(有效地重命名)前一段,赞成匹配查询。匹配查询支持单个字段,但您可以使用多重查询它支持相同的选项,并允许在多个字段上进行搜索。这个例子应该对你有帮助:
{
query:{
multi_match:{
fields:[title,subtitle],
query:试用ela,
type:phrase_prefix
}
}
}
您可以使用Java API实现相同像这样:
QueryBuilders.multiMatchQuery(试用ela,标题,subtitle)
。键入(MatchQueryBuilder.Type.PHRASE_PREFIX);
I'm new to ES and I'm trying to build a query that would use phrase_prefix for multiple fields so I dont have to search more than once.
Here's what I've got so far:
{
"query" : {
"text" : {
"first_name" : {
"query" : "Gustavo",
"type" : "phrase_prefix"
}
}
}
}'
Does anybody knows how to search for more than one field, say "last_name" ?
The text query that you are using has been deprecated (effectively renamed) a while ago in favour of the match query. The match query supports a single field, but you can use the multi_match query which supports the very same options and allows to search on multiple fields. Here is an example that should be helpful to you:
{
"query" : {
"multi_match" : {
"fields" : ["title", "subtitle"],
"query" : "trying out ela",
"type" : "phrase_prefix"
}
}
}
You can achieve the same using the Java API like this:
QueryBuilders.multiMatchQuery("trying out ela", "title", "subtitle")
.type(MatchQueryBuilder.Type.PHRASE_PREFIX);
这篇关于多个字段上的弹性搜索短语前缀查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!