栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在elasticsearch上查找具有空字符串值的文档

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在elasticsearch上查找具有空字符串值的文档

如果您使用默认的分析器(

standard
),则没有任何内容可以分析它是否为空字符串。因此,您需要逐字索引字段(未分析)。这是一个例子:

添加一个映射,该映射将为未标记的字段建立索引,如果您还需要索引的字段的标记化副本,则可以使用“
多字段”类型。

PUT http://localhost:9200/test/_mapping/demo{  "demo": {    "properties": {      "_content": {        "type": "string",        "index": "not_analyzed"      }    }  }}

接下来,索引几个文档。

/POST http://localhost:9200/test/demo/1/{  "_content": ""}/POST http://localhost:9200/test/demo/2{  "_content": "some content"}

执行搜索:

POST http://localhost:9200/test/demo/_search{  "query": {    "filtered": {      "filter": {        "term": {          "_content": ""        }      }    }  }}

返回带有空字符串的文档。

{    took: 2,    timed_out: false,    _shards: {        total: 5,        successful: 5,        failed: 0    },    hits: {        total: 1,        max_score: 0.30685282,        hits: [ {     _index: test,     _type: demo,     _id: 1,     _score: 0.30685282,     _source: {         _content: ""     } }        ]    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/382468.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号