简体   繁体   English

searchkit:RefinementListFilter无法访问json中的某些数据

[英]searchkit: RefinementListFilter can't access certain data in json

I'm usig searchkit as part of a website, but have problems in accessing my data that's been converted into json format previously. 我将usig searchkit作为网站的一部分,但在访问之前已转换为json格式的数据时遇到问题。 My json directory looks like this: 我的json目录如下所示:

(...)
hits:
   0:
    _index:           content
    _type:            content
    _source:      
          meta:
             author:  content
(...)

json JSON

and I'm using RefinementListFilter (in ReactDOM.render) and this works fine: 我正在使用RefinementListFilter(在ReactDOM.render中),这很好用:

<RefinementListFilter id="index" title="Index" field={"_index"}/>
<RefinementListFilter id="Type" title="Type" field={"_type"}/>

whereas i can't seem to access the content that is written under author: 而我似乎无法访问作者写的内容:

<RefinementListFilter id="Author" title="Author" field={"_source.meta.author"}/>

this doesn't work (no error, nothing happens when I type this), although when i use _source.meta.author in this context it works like expected: 这不起作用(没有错误,当我输入时没有任何反应),虽然当我在这个上下文中使用_source.meta.author时 ,它的工作方式与预期的一样:

class SearchHit extends React.Component {
    render() {
      const result = this.props.result;
      return (
        <div className={this.props.bemBlocks.item("author")}> <b> Index: </b> {result._index} </div>
        <div className={this.props.bemBlocks.item("author")}> <b> Author: </b> {result._source.meta.author} </div>
      )}}

What am I doing wrong? 我究竟做错了什么? The first and last snippet work just fine, it's just the middle one that doesn't. 第一个和最后一个片段工作正常,它只是中间片段没有。

The problem is within the field indices of your elasticsearch instance. 问题出在elasticsearch实例的字段索引中。 According to the docs , Searchkit needs two different kinds of indexed fields for searching and filtering. 根据文档 ,Searchkit需要两种不同类型的索引字段进行搜索和过滤。

In your case it seems like the field author is not indexed correctly. 在您的情况下,似乎字段author没有正确索引。

To solve this, you need to change the elasticsearch mapping for the field author: 要解决此问题,您需要更改字段作者的elasticsearch映射:

    ...
    "meta": {
      "properties": {
        "author": {
          "type": "text", 
            "fields": {
                "raw": {
                    "type": "keyword"
                }
            }
    ...

You can then access the authors in the Refinementfilter via 然后,您可以通过Refinementfilter访问作者

<RefinementListFilter id="author" title="Author" field={"meta.author.raw"}/>

Try to restructure your JSON file for distinct clarification. 尝试重新构建您的JSON文件以获得明确的说明。 You need two different fields for searching and filtering. 您需要两个不同的字段进行搜索和过滤。

"meta": {
      "properties": {
        "author": {
          "type": "text", 
            "fields": {
                "val": {
                    "type": "keyword"
                }
            }

While in a Refinementfilter, it can be accessed this way 在Refinementfilter中,可以通过这种方式访问​​它

<RefinementListFilter id="Author" title="Author" field={"meta.author.val"}/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM