elasticsearch - 我无法在没有属性的Elasticsearch中进行查询。<字段名称>

标签 elasticsearch elasticsearch-dsl elasticsearch-query elasticsearch-7 elasticsearch-mapping

这是用于搜索的查询:

{ "query": {
  "term": {"properties.subscriptionid": "test"
  }
    }
   } 
结果:
  
        "hits": [
            {
                "_id": "ILojbHQB1164tHwpvfoc",
                "_source": {
                    "properties": {
                        "subscriptionid": "test",
                    }
如果我使用:
{ "query": {
    "term": {"subscriptionid": "test"
    }
      }
     } 
我没有任何结果。
索引映射:
  "mappings": {
       "properties": {
         "subscriptionid": {
            "type": "keyword"
         },
         "resources":{
            "type": "nested",
}
}
*已移除,以减少代码区

最佳答案

正如@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",
        "_type": "_doc",
        "_id": "2",
        "_score": 0.2876821,
        "_source": {
          "subscriptionid": "test",
          "resources": [
            {
              "title": "elasticsearch"
            }
          ]
        }
      }
    ]

关于elasticsearch - 我无法在没有属性的Elasticsearch中进行查询。<字段名称>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63787803/

相关文章:

java - 如何将桶排序添加到查询聚合

nosql - 在 Elastic Search 上查询多级嵌套字段

elasticsearch - 使用本地卷获取错误 'unknown field hostPath' Kubernetes Elasticsearch

elasticsearch - ES_dsl.Q()中 “path”的功能是什么?

django - Elasticsearch 查询

elasticsearch - 术语与术语查询的评分不同

ElasticSearch中的Mysql等价物,根据字段更新字段

python - 如何在django_elasticsearch_dsl中像Django中的icontains一样进行真正的查询?

elasticsearch - 应该查询里面必须elasticsearch

elasticsearch - Elasticsearch 聚合和复杂查询