简体   繁体   中英

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. My json directory looks like this:

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

json

and I'm using RefinementListFilter (in ReactDOM.render) and this works fine:

<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:

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. According to the docs , Searchkit needs two different kinds of indexed fields for searching and filtering.

In your case it seems like the field author is not indexed correctly.

To solve this, you need to change the elasticsearch mapping for the field author:

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

You can then access the authors in the Refinementfilter via

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

Try to restructure your JSON file for distinct clarification. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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