gpt4 book ai didi

elasticsearch - Elasticsearch:REST API有效,但Java对应无效

转载 作者:行者123 更新时间:2023-12-03 02:08:22 24 4
gpt4 key购买 nike

我在Elastic Search中有一个文档:

{
"accountGroupId":1000,
"name":"Elastic Burgers",
"capacity":33,
"startTime":1391604480000,
"address":{
"streetName":"Rua Carlos Petit",
"streetNumber":"111",
"complement":"",
"neighborhood":"Vila Mariana",
"city":"São Paulo",
"state":"SP",
"country":"Brasil",
"zip":"04110000",
"position":{
"latitude":-23.5845048,
"longitude":-46.6358975
},
"accountGroupId":1000,
"status":[

],
"id":1000,
"createTime":1391010548111,
"updateTime":1391010548111
},
"flyerUrl":"/assets/images/placeholder-merchant.png",
"backgroundImageUrl":"/assets/images/placeholder-merchant.png",
"onSaleStartTime":1391604480000,
"onSaleEndTime":1392990480000,
"description":"Lorem Ipsum",
"eventCategoryId":1000,
"deleted":false,
"installmentId":100,
"feeId":101,
"restricted":false,
"venueAccountGroupId":15,
"updateTime":1391691790113,
"createTime":1391691790113,
"id":1002,
"venue":"Acme, Inc.",
"category":"Festa Faculdade"
}

此REST查询返回文档:
curl -XGET 'http://localhost:9200/paguemob/events/_search' -d '{
"query": {
"multi_match" : {
"query" : "festa de faculdade",
"fields" : ["name", "address.city", "venue", "category", "description"]
}
}
}'

但是,如果我通过Java API运行等效查询,则结果为空:
client
.prepareSearch(index)
.setQuery(multiMatchQuery("festa de faculdade", "name", "address.city", "venue", "category", "description"))
.setSize(200)
.execute()
.actionGet()
.getHits

我究竟做错了什么?

最佳答案

看一些ES test code,我看到除了multiMatchQuery本身,他们还将OR设置为运算符(我假设这是默认值),并将useDisMax设置为false,并设置type

   searchResponse = client().prepareSearch("test")
.setQuery(multiMatchQuery("marvel hero captain america", "full_name", "first_name", "last_name", "category")
.operator(MatchQueryBuilder.Operator.OR).useDisMax(false).type(type)).get();

我想知道其中之一是否有用?

另外,您的示例可能不会显示它,但是您是否正确访问Java中的点击结果数组?
searchResponse.getHits().hits()[0]

关于elasticsearch - Elasticsearch:REST API有效,但Java对应无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21604429/

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