gpt4 book ai didi

elasticsearch - 用 `field`查询不返回任何内容

转载 作者:行者123 更新时间:2023-12-03 00:57:15 25 4
gpt4 key购买 nike

我是 flex 搜索的新手,但查询遇到麻烦。

当我进行比赛时,我得到的一切;

{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1,
"hits": [{
"_index": "stations",
"_type": "station",
"_id": "4432",
"_score": 1,
"_source": {
"SiteName": "Abborrkroksvägen",
"LastModifiedUtcDateTime": "2015-02-13 10:34:20.643",
"ExistsFromDate": "2015-02-14 00:00:00.000"
}
},
{
"_index": "stations",
"_type": "station",
"_id": "9110",
"_score": 1,
"_source": {
"SiteName": "Abrahamsberg",
"LastModifiedUtcDateTime": "2012-03-26 23:55:32.900",
"ExistsFromDate": "2012-06-23 00:00:00.000"
}
}
]
}
}


我的搜索查询如下所示:

{
"query": {
"query_string": {
"fields": ["SiteName"],
"query": "a"
}
}
}


问题是当我运行上面的查询时,我得到的结果是空的,这很奇怪。我应该从索引中收到两个文档,对吗?

我究竟做错了什么?我是否为我的数据编制了索引错误或查询被搞砸了?

感谢我能得到的任何帮助。谢谢你们!

最佳答案

您的数据或查询都没有错。似乎您不了解如何在Elasticsearch中存储数据!

首先,当您索引数据("SiteName": "Abborrkroksvägen""SiteName": "Abrahamsberg")时,它们将被存储为单独的分析术语。

当您使用"query":"a"(means here you are looking for the term "a" )查询ES时,它将查找是否与术语a匹配,但由于没有术语,因此您将获得空结果。

当您使用"query":"a*"(means all terms starts with "a")查询ES时,它将按预期返回您。

希望这可以澄清您的问题!

关于elasticsearch - 用 `field`查询不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42443762/

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