是否可以在弹性搜索中获取copy_to字段的内容? [英] Is it possible to get contents of copy_to field in Elasticsearch?

查看:154
本文介绍了是否可以在弹性搜索中获取copy_to字段的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Elasticsearch v2.3.0。假设我有一个带映射的索引:

  {
mappings:{
post: {
dynamic:false,
_source:{
enabled:true
},
properties:{
text :{
norms:{
enabled:false
},
fielddata:{
format:disabled

analyzer:text_analyzer,
type:string
},
subfield:{
properties
subsubfield:{
properties:{
subtext:{
index:no,
analyzer:text_analyzer ,
type:string,
copy_to:text
}
}
}
}
}
},
_all:{
enabled:false
}
}
}
/ pre>

所以,由于 subfield.subsubfield.subtext 的文本被复制到文本字段由于 copy_to 。如果您查询帖子,则 text 中的数据仅显示在文本字段中,因为 _source 未修改。如果要获取所有文本,您应该聚合客户端上的所有字段。如果有很多子字段,这可能是不方便的。



是否有一个魔术查询,可以让所有文本复制到文本字段?

解决方案

文本的映射字段集存储:是
您应该可以使用字段



示例

  put test / test / _mapping 
{
properties:{
name:{type string,copy_to:text},
text:{type:string,store:yes},
subfield:{
property:{
subsubfield:{
properties:{
subtext:{
index:no,
type:string,
copy_to:text
}
}
}
}
}
}

}

put test / test / 1
{
name:hello,
子字段:{
subsubfield:[
{subtext:soundgarden},
{subtext:alice in chains},
{subtext :dio}
]
}
}

post test / _search
{
fields:[
text
]
}

结果

  {
take:2,
timed_out:false,
_shards:{
total:5,
success:5,
failed:0
},
hits:{
total:1,
max_score:1,
hits:[
{
_index:test,
_type:test,
_id:1,
_score:1,
fields:{
text:[
你好,
soun dgarden,
alice in chains,
dio
]
}
}
]
}
}


I'm using Elasticsearch v2.3.0. Suppose I have an index with mapping:

{
"mappings": {
  "post": {
    "dynamic": false,
    "_source": {
      "enabled": true
    },
    "properties": {
      "text": {
        "norms": {
          "enabled": false
        },
        "fielddata": {
          "format": "disabled"
        },
        "analyzer": "text_analyzer",
        "type": "string"
      },
      "subfield": {
        "properties": {
          "subsubfield": {
            "properties": {
              "subtext": {
                "index": "no",
                "analyzer": "text_analyzer",
                "type": "string",
                "copy_to": "text"
              }
            }  
          }
        }
      }
    },
    "_all": {
      "enabled": false
    }
  }
}

So, text from subfield.subsubfield.subtext is copied to text field due to copy_to. If you query a post, then only data from text is shown in text field, because _source is not modified. If you want to obtain all text, you should aggregate all fields on client. This can be inconvenient if there are many subfields.

Is there a magic query, which allows to get text field with all text copied to it?

解决方案

In the mapping for text field set "store":"yes" The you should be able to fetch it using fields

Example:

put test/test/_mapping
{
  "properties" : {
   "name" : { "type" : "string","copy_to": "text"},
   "text" : {"type" : "string" ,"store" :"yes"},
    "subfield": {
        "properties": {
          "subsubfield": {
            "properties": {
              "subtext": {
                "index": "no",
                "type": "string",
                "copy_to": "text"
              }
            }  
          }
        }
      }
  }   

}

put test/test/1 
{
    "name" : "hello",
    "subfield" : {
        "subsubfield" : [
            {"subtext" : "soundgarden" },
            {"subtext" : "alice in chains" },
            {"subtext" : "dio" }
        ]
    }
} 

post test/_search
{
    "fields": [
       "text"
    ]
}

Results

{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "test",
            "_type": "test",
            "_id": "1",
            "_score": 1,
            "fields": {
               "text": [
                  "hello",
                  "soundgarden",
                  "alice in chains",
                  "dio"
               ]
            }
         }
      ]
   }
}

这篇关于是否可以在弹性搜索中获取copy_to字段的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆