弹性搜索嵌套文档映射

时间:2015-06-19 11:32:13

标签: elasticsearch nested mapping

我创建了索引和映射,但是在我开始向索引添加文档后,看起来嵌套文档的映射已经改变。

在开始添加文档之前,映射是:

var cachedImages = [String:UIImage]()

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell
    let note = notes[indexPath.row]
    let url = note.valueForKey("url") as! String

    cell.textLabel!.text = note.valueForKey("title") as? String
    cell.imageView!.image = UIImage(named: "note-icon")

    if let image = cachedImages[url]{
        cell.imageView!.image = image
    } else {
        let nsURL = NSURL(string: url)!
        var loadError: NSError?

        assetsLibrary!.assetForURL(nsURL, resultBlock: { (asset) -> Void in
            if let ast = asset {
                let image = UIImage(CGImage: ast.defaultRepresentation().fullResolutionImage().takeUnretainedValue())
                self.cachedImages[url] = image

                dispatch_async(dispatch_get_main_queue(), {
                    if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
                        cellToUpdate.imageView?.image = image
                    }
                })

            }
            },failureBlock: {(error) -> Void in
                loadError = error
        })
    }
    return cell
}

开始插入文档后,映射变为:

{"products_1_1": {
    "mappings": {
      "product": {
        "properties": {
          "description": {
            "type": "string"
          },
          "metaDescription": {
            "type": "string"
          },
          "metaTitle": {
            "type": "string"
          },
          "mis_spells": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "productId": {
            "type": "integer"
          },
          "categories": {
            "type": "nested",
            "include_in_parent": true,
            "properties": {
              "default_category": {
                "type": "integer",
                "index": "no"
              },
              "filter_name": {
                "type": "string",
                "index": "not_analyzed"
              },
              "id": {
                "type": "integer"
              },
              "name": {
                "type": "string"
              },
              "parent_categories_ids": {
                "type": "string",
                "index": "no"
              },
              "parent_categories_names": {
                "type": "string",
                "index": "no"
              },
              "parent_categories_url": {
                "type": "string",
                "index": "no"
              },
              "parent_category": {
                "type": "integer",
                "index": "no"
              },
              "tags": {
                "type": "string"
              },
              "url": {
                "type": "string",
                "index": "no"
              }
            }
          }
        }
      }
    }
  }
}

有人知道为什么我的映射会以这种方式改变吗?

谢谢!

0 个答案:

没有答案