问题描述
这是用于搜索的查询:
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"
}
]
}
}
]