是否可以在弹性搜索中获取copy_to字段的内容? [英] Is it possible to get contents of copy_to field in Elasticsearch?
问题描述
{
/ pre>
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
}
}
}
所以,由于
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 textfield
due tocopy_to
. If you query a post, then only data fromtext
is shown intext
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 fieldsExample:
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屋!