是否可以在Elasticsearch中获取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
    }
  }
}
所以,从文本subfield.subsubfield.subtext复制到文本field因copy_to。如果你查询信息,然后从纯数据text显示在text现场,因为_source不被修改。如果要获取所有文本,则应汇总客户端上的所有字段。如果有许多子字段,这可能会带来不便。
是否有一个魔术查询,该查询允许获取text复制了所有文本的字段?
回答:
在text字段集的映射中,"store":"yes"
您应该能够使用字段来获取它
:
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"
    ]
}
{   "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"
               ]
            }
         }
      ]
   }
}
以上是 是否可以在Elasticsearch中获取copy_to字段的内容? 的全部内容, 来源链接: utcz.com/qa/430806.html






