gpt4 book ai didi

java - elasticsearch java搜索查询

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:14:42 27 4
gpt4 key购买 nike

我正在做一个电子商务网站,对于我的初始页面,我将放置排名前 10 位的产品。所以我正在做的是一个匹配所有的搜索查询,由 finish_dat > 而不是 +1h 过滤并将大小限制为 10(我不知道这是否是最好的方法......)

这里的事情是我想用这个查询创建一个配置(为了将来更改,比方说,到 top20,或者现在 +1d 过滤),所以我正在将查询字符串读取到一个 xml 文件中,然后然后使用 esClient.prepareSearch("products").setTypes("product").setSearchType(SearchType.QUERY_AND_FETCH).setQuery(myQuery).execute().actionGet();

问题是我正在尝试使用 curl 中的正文查询:

{  "sort" : [
{ "finish_date" : {"order" : "asc"}}
],
"query" : {"match_all" : {}},
"filter": {
"range": {
"finish_date": {
"from": "now+1h"
}
}
}

报错

Root cause is: Failed to execute phase [query_fetch], all shards failed; shardFailures {[lWQlkEM_QQCJY0RzHBz_vw][auction][4]: RemoteTransportException[[MODAM][inet[/192.168.1.4:9301]][search/phase/query+fetch]]; nested: SearchParseException[[auction][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"InNvcnQiIDogW3sgImZpbmlzaF9kYXRlIiA6IHsib3JkZXIiIDogImFzYyJ9fV0sInF1ZXJ5IiA6IHsibWF0Y2hfYWxsIiA6IHt9fSwiZmlsdGVyIjogeyJyYW5nZSI6IHsiZmluaXNoX2RhdGUiOiB7ImZyb20iOiAibm93KzFoIn19fSwgImZyb20iIDogMCwgInNpemUiIDogMTA="}]]]; nested: QueryParsingException[[auction] [_na] query malformed, must start with start_object]; }{[Ltw-Ez47SD6WkLgON6kvHQ][auction][3]: SearchParseException[[auction][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"InNvcnQiIDogW3sgImZpbmlzaF9kYXRlIiA6IHsib3JkZXIiIDogImFzYyJ9fV0sInF1ZXJ5IiA6IHsibWF0Y2hfYWxsIiA6IHt9fSwiZmlsdGVyIjogeyJyYW5nZSI6IHsiZmluaXNoX2RhdGUiOiB7ImZyb20iOiAibm93KzFoIn19fSwgImZyb20iIDogMCwgInNpemUiIDogMTA="}]]]; nested: QueryParsingException[[auction] [_na] query malformed, must start with start_object]; }{[Ltw-Ez47SD6WkLgON6kvHQ][auction][1]: SearchParseException[[auction][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"InNvcnQiIDogW3sgImZpbmlzaF9kYXRlIiA6IHsib3JkZXIiIDogImFzYyJ9fV0sInF1ZXJ5IiA6IHsibWF0Y2hfYWxsIiA6IHt9fSwiZmlsdGVyIjogeyJyYW5nZSI6IHsiZmluaXNoX2RhdGUiOiB7ImZyb20iOiAibm93KzFoIn19fSwgImZyb20iIDogMCwgInNpemUiIDogMTA="}]]]; nested: QueryParsingException[[auction] [_na] query malformed, must start with start_object]; }{[Ltw-Ez47SD6WkLgON6kvHQ][auction][2]: SearchParseException[[auction][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"InNvcnQiIDogW3sgImZpbmlzaF9kYXRlIiA6IHsib3JkZXIiIDogImFzYyJ9fV0sInF1ZXJ5IiA6IHsibWF0Y2hfYWxsIiA6IHt9fSwiZmlsdGVyIjogeyJyYW5nZSI6IHsiZmluaXNoX2RhdGUiOiB7ImZyb20iOiAibm93KzFoIn19fSwgImZyb20iIDogMCwgInNpemUiIDogMTA="}]]]; nested: QueryParsingException[[auction] [_na] query malformed, must start with start_object]; }{[Ltw-Ez47SD6WkLgON6kvHQ][auction][0]: SearchParseException[[auction][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"InNvcnQiIDogW3sgImZpbmlzaF9kYXRlIiA6IHsib3JkZXIiIDogImFzYyJ9fV0sInF1ZXJ5IiA6IHsibWF0Y2hfYWxsIiA6IHt9fSwiZmlsdGVyIjogeyJyYW5nZSI6IHsiZmluaXNoX2RhdGUiOiB7ImZyb20iOiAibm93KzFoIn19fSwgImZyb20iIDogMCwgInNpemUiIDogMTA="}]]]; nested: QueryParsingException[[auction] [_na] query malformed, must start with start_object]; } org.elasticsearch.action.search.SearchPhaseExecutionException: Failed to execute phase [query_fetch], all shards failed; shardFailures {[lWQlkEM_QQCJY0RzHBz_vw][auction][4]: RemoteTransportException[[MODAM][inet[/192.168.1.4:9301]][search/phase/query+fetch]]; nested: SearchParseException[[auction][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"InNvcnQiIDogW3sgImZpbmlzaF9kYXRlIiA6IHsib3JkZXIiIDogImFzYyJ9fV0sInF1ZXJ5IiA6IHsibWF0Y2hfYWxsIiA6IHt9fSwiZmlsdGVyIjogeyJyYW5nZSI6IHsiZmluaXNoX2RhdGUiOiB7ImZyb20iOiAibm93KzFoIn19fSwgImZyb20iIDogMCwgInNpemUiIDogMTA="}]]]; nested: QueryParsingException[[auction] [_na] query malformed, must start with start_object]; }{[Ltw-Ez47SD6WkLgON6kvHQ][auction][3]: SearchParseException[[auction][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"InNvcnQiIDogW3sgImZpbmlzaF9kYXRlIiA6IHsib3JkZXIiIDogImFzYyJ9fV0sInF1ZXJ5IiA6IHsibWF0Y2hfYWxsIiA6IHt9fSwiZmlsdGVyIjogeyJyYW5nZSI6IHsiZmluaXNoX2RhdGUiOiB7ImZyb20iOiAibm93KzFoIn19fSwgImZyb20iIDogMCwgInNpemUiIDogMTA="}]]]; nested: QueryParsingException[[auction] [_na] query malformed, must start with start_object]; }{[Ltw-Ez47SD6WkLgON6kvHQ][auction][1]: SearchParseException[[auction][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"InNvcnQiIDogW3sgImZpbmlzaF9kYXRlIiA6IHsib3JkZXIiIDogImFzYyJ9fV0sInF1ZXJ5IiA6IHsibWF0Y2hfYWxsIiA6IHt9fSwiZmlsdGVyIjogeyJyYW5nZSI6IHsiZmluaXNoX2RhdGUiOiB7ImZyb20iOiAibm93KzFoIn19fSwgImZyb20iIDogMCwgInNpemUiIDogMTA="}]]]; nested: QueryParsingException[[auction] [_na] query malformed, must start with start_object]; }{[Ltw-Ez47SD6WkLgON6kvHQ][auction][2]: SearchParseException[[auction][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"InNvcnQiIDogW3sgImZpbmlzaF9kYXRlIiA6IHsib3JkZXIiIDogImFzYyJ9fV0sInF1ZXJ5IiA6IHsibWF0Y2hfYWxsIiA6IHt9fSwiZmlsdGVyIjogeyJyYW5nZSI6IHsiZmluaXNoX2RhdGUiOiB7ImZyb20iOiAibm93KzFoIn19fSwgImZyb20iIDogMCwgInNpemUiIDogMTA="}]]]; nested: QueryParsingException[[auction] [_na] query malformed, must start with start_object]; }{[Ltw-Ez47SD6WkLgON6kvHQ][auction][0]: SearchParseException[[auction][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query_binary":"InNvcnQiIDogW3sgImZpbmlzaF9kYXRlIiA6IHsib3JkZXIiIDogImFzYyJ9fV0sInF1ZXJ5IiA6IHsibWF0Y2hfYWxsIiA6IHt9fSwiZmlsdGVyIjogeyJyYW5nZSI6IHsiZmluaXNoX2RhdGUiOiB7ImZyb20iOiAibm93KzFoIn19fSwgImZyb20iIDogMCwgInNpemUiIDogMTA="}]]]; nested: QueryParsingException[[auction] [_na] query malformed, must start with start_object]; } at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.onFirstPhaseResult(TransportSearchTypeAction.java:272) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$3.onFailure(TransportSearchTypeAction.java:224) at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteFetch(SearchServiceTransportAction.java:307) at org.elasticsearch.action.search.type.TransportSearchQueryAndFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryAndFetchAction.java:71) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216) at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$4.run(TransportSearchTypeAction.java:292) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) 

有人知道怎么做吗? (一个例子或指向正确的方向)??

提前致谢

最佳答案

你需要使用模板查询,这是官方支持的做你想做的事情的方式,它也支持将模板存储在文件系统上,但作为 mustache 模板而不是 XML。

您可以在 http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-template-query.html 阅读有关模板查询的更多信息.

您实际上不需要将 mustache 安装到您的项目中,但如果您对它感兴趣,可以在 http://mustache.github.io/ 阅读更多相关信息。 .他们甚至有它的 Java 版本,https://github.com/spullara/mustache.java .

关于java - elasticsearch java搜索查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22283559/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com