在弹性搜索中使用query_string查询与bool导致解析异常 [英] using query_string query with bool in elastic search causing parsing exception
问题描述
{
查询:{
filtered:{
query:{
bool:{
must:[
{
terms:{
status_type
5
]
}
}
]
}
},
过滤器:{
query_string:{
fields:[
[
name,
message
]
],
查询:阿诺德和施瓦茨
}
}
}
},
sort:[
{
total_metrics:{
order:desc
}
}
]
}
您应该使用查询过滤器,将任何查询包装到过滤器中。否则您将得到解析错误没有为[query_string]注册过滤器
。
您需要更改过滤器
部分到:
filter:{
query:{//< - 将查询作为过滤器
query_string:{
fields:[
[
name,
消息
]
],
查询:阿诺德和施瓦茨
}
}
}
@Edit:由于我看到人们可能会遇到问题,注意到我只粘贴了整个查询的更改部分,包括过滤器
部分(不是整个过滤
)修改后的整个事情:
{
query:{
filtered:{
query:{
bool:{
必须:[
{
条款:{
status_type:[
5
]
}
}
]
}
},
filter :{
query:{//< - 唯一的区别!
query_string:{
fields:[
[
name,
message
]
],
查询:阿诺德和施瓦茨
}
}
}
}
},
sort:[
{
total_metrics:{
order:desc
}
}
]
}
Why is this query giving me a parsing exception? If I remove the bool it does seem to work. But I need the bool there with the query_string. How can I make this work?
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"terms": {
"status_type": [
"5"
]
}
}
]
}
},
"filter": {
"query_string": {
"fields": [
[
"name",
"message"
]
],
"query": "Arnold AND Schwarz"
}
}
}
},
"sort": [
{
"total_metrics": {
"order": "desc"
}
}
]
}
You should use the query filter which wraps any query into a filter. Otherwise you will get the parse error you get No filter registered for [query_string]
.
You need to change your filter
part to:
"filter": {
"query": { // <- wraps a query as a filter
"query_string": {
"fields": [
[
"name",
"message"
]
],
"query": "Arnold AND Schwarz"
}
}
}
@Edit: since I see people might have problems noticing that I only pasted the changed part of the whole query including the filter
part (not the whole filtered
) here's the whole thing after modification:
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"terms": {
"status_type": [
"5"
]
}
}
]
}
},
"filter": {
"query": { // <- the only difference!
"query_string": {
"fields": [
[
"name",
"message"
]
],
"query": "Arnold AND Schwarz"
}
}
}
}
},
"sort": [
{
"total_metrics": {
"order": "desc"
}
}
]
}
这篇关于在弹性搜索中使用query_string查询与bool导致解析异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!