我无法在没有属性的弹性搜索中进行查询<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"
            }
          ]
        }
      }
    ]

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...