簡體   English   中英

ElasticSearch Java API搜索錯誤

[英]ElasticSearch Java API Search Error

每個searchRequest.toString()和每個錯誤信息。

我認為,如果您在檢查那些搜索內容和錯誤之前在底部看到摘要,應該更容易理解我的問題。

搜索身體

{
"from" : 0,
"size" : 12,
"query" : {
    "custom_filters_score" : {
        "query" : {
            "bool" : {
                "must" : {
                    "term" : {
                        "2474" : [ "20", "17" ]
                    }
                },
                "should" : {
                    "term" : {
                        "productName" : {
                            "value" : "xxx",
                            "boost" : 3.0
                        }
                    }
                }
            }
        },
        "filters" : [ {
            "filter" : {
                "terms" : {
                    "availableStock" : [ 0 ]
                }
            },
            "boost" : -10.0
        } ]
    }
},
"filter" : {
    "bool" : {
        "must_not" : {
            "term" : {
                "ecPrice" : -1
            }
        }
    }
},
"sort" : [ {
    "_score" : {
        "order" : "desc"
    }
} ],
"facets" : {
    "productBrandName" : {
        "terms" : {
            "field" : "productBrandName",
            "size" : 10
        }
    }
},
"highlight" : {
    "pre_tags" : [ "<font style='color:red'>" ],
    "post_tags" : [ "</font>" ],
    "fields" : {
        "productName" : { },
        "drugTreatment" : { }
    }
}

}

錯誤:

 QueryParsingException[[hy_index] [bool] query does not support [must]];

搜索身體

{
"from" : 0,
"size" : 12,
"query" : {
    "custom_filters_score" : {
        "query" : {
            "bool" : {
                "should" : {
                    "term" : {
                        "2474" : [ "20", "17" ]
                    }
                }
            }
        },
        "filters" : [ ]
    }
},
"filter" : {
    "bool" : {
        "must_not" : {
            "term" : {
                "ecPrice" : -1
            }
        }
    }
},
"sort" : [ {
    "_score" : {
        "order" : "desc"
    }
} ],
"facets" : {
    "productBrandName" : {
        "terms" : {
            "field" : "productBrandName",
            "size" : 10
        }
    }
},
"highlight" : {
    "pre_tags" : [ "<font style='color:red'>" ],
    "post_tags" : [ "</font>" ],
    "fields" : {
        "productName" : { },
        "drugTreatment" : { }
    }
}

}

錯誤

QueryParsingException[[hy_index] [bool] query does not support [should]]

搜索身體

{
"from" : 0,
"size" : 12,
"query" : {
    "custom_filters_score" : {
        "query" : {
            "bool" : {
                "should" : [ {
                    "term" : {
                        "productName" : {
                            "value" : "xxx",
                            "boost" : 3.0
                        }
                    }
                }, {
                    "term" : {
                        "2474" : [ "20", "17" ]
                    }
                } ]
            }
        },
        "filters" : [ {
            "filter" : {
                "terms" : {
                    "availableStock" : [ 0 ]
                }
            },
            "boost" : -10.0
        } ]
    }
},
"filter" : {
    "bool" : {
        "must_not" : {
            "term" : {
                "ecPrice" : -1
            }
        }
    }
},
"sort" : [ {
    "_score" : {
        "order" : "desc"
    }
} ],
"facets" : {
    "productBrandName" : {
        "terms" : {
            "field" : "productBrandName",
            "size" : 10
        }
    }
},
"highlight" : {
    "pre_tags" : [ "<font style='color:red'>" ],
    "post_tags" : [ "</font>" ],
    "fields" : {
        "productName" : { },
        "drugTreatment" : { }
    }
}

}

錯誤

QueryParsingException[[hy_index] [_na] query malformed, must start with start_object];

搜索身體

{
"from" : 0,
"size" : 12,
"query" : {
    "custom_filters_score" : {
        "query" : {
            "bool" : {
                "should" : {
                    "term" : {
                        "productName" : {
                            "value" : "撒",
                            "boost" : 3.0
                        }
                    }
                }
            }
        },
        "filters" : [ {
            "filter" : {
                "terms" : {
                    "availableStock" : [ 0 ]
                }
            },
            "boost" : -10.0
        } ]
    }
},
"filter" : {
    "bool" : {
        "must_not" : {
            "term" : {
                "ecPrice" : -1
            }
        }
    }
},
"sort" : [ {
    "_score" : {
        "order" : "desc"
    }
} ],
"facets" : {
    "productBrandName" : {
        "terms" : {
            "field" : "productBrandName",
            "size" : 10
        }
    }
},
"highlight" : {
    "pre_tags" : [ "<font style='color:red'>" ],
    "post_tags" : [ "</font>" ],
    "fields" : {
        "productName" : { },
        "drugTreatment" : { }
    }
}

}

這沒有錯誤。

現在,總結。

無論我使用"term" : {"2474" : [ "20", "17" ]} should還是must

當我在查詢正文中設置"term" : {"2474" : [ "20", "17" ]}時,總是會出錯。

一旦我從查詢正文中刪除了"term" : {"2474" : [ "20", "17" ]} ,它就可以正常工作。

為什么?

字詞查詢只需要一個值。 術語意味着一個以上的價值。請嘗試一下

 "terms" : {"2474" : [ "20", "17" ]}

將術語查詢更改為術語。請參考以下網址, http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM