<h1 dir="auto">Checklist</h1>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> This has already been asked to the <a href="https://github.com/celery/celery/discussions">discussions forum</a> first.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have read the relevant section in the<br>
<a href="http://docs.celeryproject.org/en/latest/contributing.html#other-bugs" rel="nofollow">contribution guide</a><br>
on reporting bugs.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22">issues list</a><br>
for similar or identical bug reports.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/commits/master">commit log</a><br>
to find out if the bug was already fixed in the master branch.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all related issues and possible duplicate issues<br>
in this issue (If there are none, check this box anyway).</li>
</ul>
<h2 dir="auto">Mandatory Debugging Information</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the output of <code class="notranslate">celery -A proj report</code> in the issue.<br>
(if you are not able to do this, then at least specify the Celery<br>
version affected).</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included the contents of <code class="notranslate">pip freeze</code> in the issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included all the versions of all the external dependencies required<br>
to reproduce this bug.</li>
</ul>
<h2 dir="auto">Optional Debugging Information</h2>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one Python version<br>
and/or implementation.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one message broker and/or<br>
result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one version of the message<br>
broker and/or result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one operating system.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one workers pool.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue with autoscaling, retries,<br>
ETA/Countdown &amp; rate limits disabled.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue after downgrading<br>
and/or upgrading Celery and its dependencies.</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li><a href="https://github.com/celery/celery/pull/6838" data-hovercard-type="pull_request" data-hovercard-url="/celery/celery/pull/6838/hovercard">Created in PR #6838</a></li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h2 dir="auto">Environment &amp; Settings</h2>

<p dir="auto"><strong>Celery version</strong>: 5.2.0</p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TypeError: a bytes-like object is required, not 'str'
  File &quot;aspiredu/project/celery.py&quot;, line 43, in run_command
    sys.stdout.write(line)  # Write all output from the command
  File &quot;celery/utils/log.py&quot;, line 227, in write
    data = data.rstrip('\n')"><pre class="notranslate"><code class="notranslate">TypeError: a bytes-like object is required, not 'str'
  File "aspiredu/project/celery.py", line 43, in run_command
    sys.stdout.write(line)  # Write all output from the command
  File "celery/utils/log.py", line 227, in write
    data = data.rstrip('\n')
</code></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Steps to Reproduce</h1>
<h2 dir="auto">Required Dependencies</h2>

<ul dir="auto">
<li><strong>Minimal Python Version</strong>: 3.9.6</li>
<li><strong>Minimal Celery Version</strong>: 5.2</li>
<li><strong>Minimal Kombu Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Version</strong>: N/A or Unknown</li>
<li><strong>Minimal OS and/or Kernel Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Client Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Client Version</strong>: N/A or Unknown</li>
</ul>
<h3 dir="auto">Python Packages</h3>

<details>
<summary><b><code class="notranslate">pip freeze</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="scout_apm==2.23.3"><pre class="notranslate"><code class="notranslate">scout_apm==2.23.3
</code></pre></div>
<p dir="auto"></p>
</details>
<h3 dir="auto">Other Dependencies</h3>

<details>
<p dir="auto">
N/A
</p>
</details>
<h2 dir="auto">Minimally Reproducible Test Case</h2>

<details>
<p dir="auto">
</p><p dir="auto">Add the following test to t.unit.app.test_log.test_default_logger</p>
<p dir="auto">What's happening is that the logger is getting a data instance of type bytes, but can call rstrip with a <code class="notranslate">str</code> parameter which breaks.</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    @mock.restore_logging()
    def test_logging_proxy_bytes(self):
        logger = self.setup_logger(loglevel=logging.ERROR, logfile=None,
                                   root=False)

        with mock.wrap_logger(logger) as sio:
            p = LoggingProxy(logger, loglevel=logging.ERROR)
            p.close()
            p.write(b'foo')
            assert 'foo' not in str(sio.getvalue())
            p.closed = False
            p.write(b'\n')
            assert str(sio.getvalue()) == ''
            write_res = p.write(b'foo ')
            assert str(sio.getvalue()) == 'foo \n'
            assert write_res == 4
            p.flush()
            p.close()
            assert not p.isatty()

            with mock.stdouts() as (stdout, stderr):
                with in_sighandler():
                    p.write(b'foo')
                    assert stderr.getvalue()
"><pre class="notranslate">    <span class="pl-en">@<span class="pl-s1">mock</span>.<span class="pl-en">restore_logging</span>()</span>
    <span class="pl-k">def</span> <span class="pl-en">test_logging_proxy_bytes</span>(<span class="pl-s1">self</span>):
        <span class="pl-s1">logger</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">setup_logger</span>(<span class="pl-s1">loglevel</span><span class="pl-c1">=</span><span class="pl-s1">logging</span>.<span class="pl-v">ERROR</span>, <span class="pl-s1">logfile</span><span class="pl-c1">=</span><span class="pl-c1">None</span>,
                                   <span class="pl-s1">root</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)

        <span class="pl-k">with</span> <span class="pl-s1">mock</span>.<span class="pl-en">wrap_logger</span>(<span class="pl-s1">logger</span>) <span class="pl-k">as</span> <span class="pl-s1">sio</span>:
            <span class="pl-s1">p</span> <span class="pl-c1">=</span> <span class="pl-v">LoggingProxy</span>(<span class="pl-s1">logger</span>, <span class="pl-s1">loglevel</span><span class="pl-c1">=</span><span class="pl-s1">logging</span>.<span class="pl-v">ERROR</span>)
            <span class="pl-s1">p</span>.<span class="pl-en">close</span>()
            <span class="pl-s1">p</span>.<span class="pl-en">write</span>(<span class="pl-s">b'foo'</span>)
            <span class="pl-k">assert</span> <span class="pl-s">'foo'</span> <span class="pl-c1">not</span> <span class="pl-c1">in</span> <span class="pl-en">str</span>(<span class="pl-s1">sio</span>.<span class="pl-en">getvalue</span>())
            <span class="pl-s1">p</span>.<span class="pl-s1">closed</span> <span class="pl-c1">=</span> <span class="pl-c1">False</span>
            <span class="pl-s1">p</span>.<span class="pl-en">write</span>(<span class="pl-s">b'<span class="pl-cce">\n</span>'</span>)
            <span class="pl-k">assert</span> <span class="pl-en">str</span>(<span class="pl-s1">sio</span>.<span class="pl-en">getvalue</span>()) <span class="pl-c1">==</span> <span class="pl-s">''</span>
            <span class="pl-s1">write_res</span> <span class="pl-c1">=</span> <span class="pl-s1">p</span>.<span class="pl-en">write</span>(<span class="pl-s">b'foo '</span>)
            <span class="pl-k">assert</span> <span class="pl-en">str</span>(<span class="pl-s1">sio</span>.<span class="pl-en">getvalue</span>()) <span class="pl-c1">==</span> <span class="pl-s">'foo <span class="pl-cce">\n</span>'</span>
            <span class="pl-k">assert</span> <span class="pl-s1">write_res</span> <span class="pl-c1">==</span> <span class="pl-c1">4</span>
            <span class="pl-s1">p</span>.<span class="pl-en">flush</span>()
            <span class="pl-s1">p</span>.<span class="pl-en">close</span>()
            <span class="pl-k">assert</span> <span class="pl-c1">not</span> <span class="pl-s1">p</span>.<span class="pl-en">isatty</span>()

            <span class="pl-k">with</span> <span class="pl-s1">mock</span>.<span class="pl-en">stdouts</span>() <span class="pl-k">as</span> (<span class="pl-s1">stdout</span>, <span class="pl-s1">stderr</span>):
                <span class="pl-k">with</span> <span class="pl-en">in_sighandler</span>():
                    <span class="pl-s1">p</span>.<span class="pl-en">write</span>(<span class="pl-s">b'foo'</span>)
                    <span class="pl-k">assert</span> <span class="pl-s1">stderr</span>.<span class="pl-en">getvalue</span>()</pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>

<p dir="auto">Calling <code class="notranslate">ProxyLogger(logger).write(b'value')</code> should not break when a bytes instance is passed in.</p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">A <code class="notranslate">TypeError: a bytes-like object is required, not 'str'</code> is raised.</p>
<p dir="auto">I will be creating a PR as a follow-up to this issue.</p>
<h1 dir="auto">Checklist</h1>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have read the relevant section in the<br>
<a href="http://docs.celeryproject.org/en/latest/contributing.html#other-bugs" rel="nofollow">contribution guide</a><br>
on reporting bugs.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22">issues list</a><br>
for similar or identical bug reports.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/commits/master">commit log</a><br>
to find out if the bug was already fixed in the master branch.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all related issues and possible duplicate issues<br>
in this issue (If there are none, check this box anyway).</li>
</ul>
<h2 dir="auto">Mandatory Debugging Information</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the output of <code class="notranslate">celery -A proj report</code> in the issue.<br>
(if you are not able to do this, then at least specify the Celery<br>
version affected).</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included the contents of <code class="notranslate">pip freeze</code> in the issue.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have included all the versions of all the external dependencies required<br>
to reproduce this bug.</li>
</ul>
<h2 dir="auto">Optional Debugging Information</h2>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one Python version<br>
and/or implementation.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one message broker and/or<br>
result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one version of the message<br>
broker and/or result backend.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one operating system.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue on more than one workers pool.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue with autoscaling, retries,<br>
ETA/Countdown &amp; rate limits disabled.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have tried reproducing the issue after downgrading<br>
and/or upgrading Celery and its dependencies.</li>
</ul>
<h2 dir="auto">Related Issues and Possible Duplicates</h2>

<h4 dir="auto">Related Issues</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li>None</li>
</ul>
<h2 dir="auto">Environment &amp; Settings</h2>

<p dir="auto"><strong>Celery version</strong>: 4.3.0</p>

<details>
<summary><b><code class="notranslate">celery report</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate"></code></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Steps to Reproduce</h1>
<p dir="auto">Add elasticsearch as backend<br>
Run any command</p>
<h2 dir="auto">Required Dependencies</h2>

<ul dir="auto">
<li><strong>Minimal Python Version</strong>: '3.7.1 (default, Nov  6 2018, 18:46:03) \n[Clang 10.0.0 (clang-1000.11.45.5)]'</li>
<li><strong>Minimal Celery Version</strong>: 4.3.0</li>
<li><strong>Minimal Kombu Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Broker Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Version</strong>: N/A or Unknown</li>
<li><strong>Minimal OS and/or Kernel Version</strong>: System Version: macOS 10.14.5 (18F132) Darwin 18.6.0</li>
<li><strong>Minimal Broker Client Version</strong>: N/A or Unknown</li>
<li><strong>Minimal Result Backend Client Version</strong>: Elasticsearch 7.0.0</li>
</ul>
<h3 dir="auto">Python Packages</h3>

<details>
<summary><b><code class="notranslate">pip freeze</code> Output:</b></summary>
<p dir="auto">
</p><div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"><code class="notranslate"></code></pre></div>
<p dir="auto"></p>
</details>
<h3 dir="auto">Other Dependencies</h3>

<details>
<p dir="auto">
N/A
</p>
</details>
<h2 dir="auto">Minimally Reproducible Test Case</h2>

<details>
<p dir="auto">
</p><div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content=""><pre class="notranslate"></pre></div>
<p dir="auto"></p>
</details>
<h1 dir="auto">Expected Behavior</h1>

<p dir="auto">Result is sent as a dictionary. At <code class="notranslate">body</code> dictionary creation, result added as inner dictionary, not as a string. Correct mapping is created. Results in Elasticsearch will be shown correctly and nested type could be used.</p>
<p dir="auto">Correct mapping example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;celery&quot; : {
    &quot;mappings&quot; : {
      &quot;backend&quot; : {
        &quot;properties&quot; : {
          &quot;@timestamp&quot; : {
            &quot;type&quot; : &quot;date&quot;
          },
          &quot;result&quot; : {
            &quot;properties&quot; : {
              &quot;date_done&quot; : {
                &quot;type&quot; : &quot;date&quot;
              },
              &quot;result&quot; : {
                &quot;type&quot; : &quot;long&quot;
              },
              &quot;status&quot; : {
                &quot;type&quot; : &quot;text&quot;,
                &quot;fields&quot; : {
                  &quot;keyword&quot; : {
                    &quot;type&quot; : &quot;keyword&quot;,
                    &quot;ignore_above&quot; : 256
                  }
                }
              },
              &quot;task_id&quot; : {
                &quot;type&quot; : &quot;text&quot;,
                &quot;fields&quot; : {
                  &quot;keyword&quot; : {
                    &quot;type&quot; : &quot;keyword&quot;,
                    &quot;ignore_above&quot; : 256
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">{
  "celery" : {
    "mappings" : {
      "backend" : {
        "properties" : {
          "@timestamp" : {
            "type" : "date"
          },
          "result" : {
            "properties" : {
              "date_done" : {
                "type" : "date"
              },
              "result" : {
                "type" : "long"
              },
              "status" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "task_id" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
</code></pre></div>
<p dir="auto">Kibana:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/375964/61964080-c20c6d80-afd5-11e9-8506-90e19518b178.png"><img width="1410" alt="Screenshot 2019-07-26 at 17 49 27" src="https://user-images.githubusercontent.com/375964/61964080-c20c6d80-afd5-11e9-8506-90e19518b178.png" style="max-width: 100%;"></a></p>
<h1 dir="auto">Actual Behavior</h1>

<p dir="auto">Result value is serialized into a JSON string. At <code class="notranslate">body</code> dictionary creation, result added as a string. Elasticsearch can't parse it correctly.</p>
<p dir="auto">Actual mapping:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{
  &quot;celery&quot; : {
    &quot;mappings&quot; : {
      &quot;backend&quot; : {
        &quot;properties&quot; : {
          &quot;@timestamp&quot; : {
            &quot;type&quot; : &quot;date&quot;
          },
          &quot;result&quot; : {
            &quot;type&quot; : &quot;text&quot;,
            &quot;fields&quot; : {
              &quot;keyword&quot; : {
                &quot;type&quot; : &quot;keyword&quot;,
                &quot;ignore_above&quot; : 256
              }
            }
          }
        }
      }
    }
  }
}"><pre class="notranslate"><code class="notranslate">{
  "celery" : {
    "mappings" : {
      "backend" : {
        "properties" : {
          "@timestamp" : {
            "type" : "date"
          },
          "result" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
  }
}
</code></pre></div>
<p dir="auto">Kibana:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/375964/61964068-bae55f80-afd5-11e9-9c31-46a11892c830.png"><img src="https://user-images.githubusercontent.com/375964/61964068-bae55f80-afd5-11e9-9c31-46a11892c830.png" alt="Screenshot 2019-07-24 at 20 30 41" style="max-width: 100%;"></a></p>
<p dir="auto"><a href="https://stackoverflow.com/questions/57188494/celery-result-type-for-elasticsearch" rel="nofollow">My stackoverflow question</a></p>
<h1 dir="auto">Solution</h1>
<p dir="auto">In my fork I've imported <code class="notranslate">json package</code> and  added <code class="notranslate">json.loads(value)</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# celery/backends/elasticsearch.py
import json

def set(self, key, value):
        try:
            self._index(
                id=key,
                body={
                    'result': json.loads(value),
                    '@timestamp': '{0}Z'.format(
                        datetime.utcnow().isoformat()[:-3]
                    ),
                },
            )
        except elasticsearch.exceptions.ConflictError:
            # document already exists, update it
            data = self.get(key)
            data[key] = value
            self._index(key, data, refresh=True)"><pre class="notranslate"><code class="notranslate"># celery/backends/elasticsearch.py
import json

def set(self, key, value):
        try:
            self._index(
                id=key,
                body={
                    'result': json.loads(value),
                    '@timestamp': '{0}Z'.format(
                        datetime.utcnow().isoformat()[:-3]
                    ),
                },
            )
        except elasticsearch.exceptions.ConflictError:
            # document already exists, update it
            data = self.get(key)
            data[key] = value
            self._index(key, data, refresh=True)
</code></pre></div>
<p dir="auto">Is there a way to disable JSON serialization of results for the Elasticsearch backend? If no, is this solution good enough for the pull-request?</p>