1<?php
2
3namespace Elastica\Processor;
4
5/**
6 * Elastica Json Processor.
7 *
8 * @author Federico Panini <fpanini@gmail.com>
9 *
10 * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/json-processor.html
11 */
12class Json extends AbstractProcessor
13{
14    const DEFAULT_TARGET_FIELD_VALUE = 'field';
15    const DEFAULT_ADD_TO_ROOT_VALUE = false;
16
17    /**
18     * Json constructor.
19     *
20     * @param string $field
21     */
22    public function __construct(string $field)
23    {
24        $this->setField($field);
25    }
26
27    /**
28     * Set the field.
29     *
30     * @param string $field
31     *
32     * @return $this
33     */
34    public function setField(string $field): self
35    {
36        return $this->setParam('field', $field);
37    }
38
39    /**
40     * Set target_field. Default field.
41     *
42     * @param string $targetField
43     *
44     * @return $this
45     */
46    public function setTargetField(string $targetField): self
47    {
48        return $this->setParam('target_field', $targetField);
49    }
50
51    /**
52     * Set add_to_root. Default value false.
53     *
54     * @param bool $addToRoot
55     *
56     * @return $this
57     */
58    public function setAddToRoot(bool $addToRoot): self
59    {
60        return $this->setParam('add_to_root', $addToRoot);
61    }
62}
63