【问题标题】:I am not able to query in elastic search with out properties.<fieldname>我无法在没有属性的情况下在弹性搜索中进行查询。<fieldname>
【发布时间】:2020-12-26 11:30:03
【问题描述】:

这是用于搜索的查询:

{ "query": {
  "term": {"properties.subscriptionid": "test"
  }
    }
   } 

结果:

  
        "hits": [
            {
                "_id": "ILojbHQB1164tHwpvfoc",
                "_source": {
                    "properties": {
                        "subscriptionid": "test",
                    }

如果我使用:

{ "query": {
    "term": {"subscriptionid": "test"
    }
      }
     } 

我没有得到任何结果。

索引映射:

  "mappings": {
       "properties": {
         "subscriptionid": {
            "type": "keyword"
         },
         "resources":{
            "type": "nested",
}
}

*删除不需要减少代码区域

【问题讨论】:

  • 我很确定您的有效映射与您认为已安装的映射不同。您能否展示运行GET your-index 时得到的结果并用结果更新您的问题?
  • 是的,当插入 _doc 时,索引发生了变化,谢谢兄弟!!!
  • 是的,因为您索引的文档包含properties 哈希,根据您的映射,它不应该,只需删除该部分就可以了。

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


【解决方案1】:

正如@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"
            }
          ]
        }
      }
    ]

【讨论】:

  • @Panther_11 你有机会看我的回答吗,期待得到你的反馈:)
猜你喜欢
  • 1970-01-01
  • 2019-11-15
  • 1970-01-01
  • 1970-01-01
  • 2014-09-29
  • 2017-09-28
  • 2019-12-22
  • 2014-12-13
  • 1970-01-01
相关资源
最近更新 更多