如何解决我无法在没有属性的弹性搜索中进行查询<fieldname>
这是用于搜索的查询:
y
结果:
{ "query": {
"term": {"properties.subscriptionid": "test"
}
}
}
如果我使用:
"hits": [
{
"_id": "ILojbHQB1164tHwpvfoc","_source": {
"properties": {
"subscriptionid": "test",}
我没有任何结果。
索引映射:
{ "query": {
"term": {"subscriptionid": "test"
}
}
}
*已删除,无需缩小代码区域
解决方法
正如@Val指出的那样,您在问题中发布的索引映射中有些不匹配。请参阅terms query,以获取详细的了解。
添加带有索引数据,映射(与问题中提到的相同)和搜索查询的工作示例。
索引映射:
{
"mappings": {
"properties": {
"resources": {
"type": "nested"
},"subscriptionid": {
"type": "keyword"
}
}
}
}
索引数据:
{
"subscriptionid": "test","resources": [
{
"title": "elasticsearch"
}
]
}
{
"subscriptionid": "test"
}
搜索查询:
{
"query": {
"term": {
"subscriptionid": "test"
}
}
}
搜索结果:
"hits": [
{
"_index": "stof","_type": "_doc","_id": "1","_score": 0.2876821,"_source": {
"subscriptionid": "test"
}
}
]
使用词条查询搜索嵌套类型的查询:
{
"query": {
"nested": {
"path": "resources","query": {
"bool": {
"must": [
{ "term": { "resources.title": "elasticsearch" } }
]
}
}
}
}
}
嵌套映射的搜索结果:
"hits": [
{
"_index": "stof","_id": "2","_source": {
"subscriptionid": "test","resources": [
{
"title": "elasticsearch"
}
]
}
}
]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。