Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 696
Julia Ktitareva Avatar asked Jan 22 '26 18:01

Julia Ktitareva


1 Answers

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"}/>
like image 136
Jones1220 Avatar answered Jan 25 '26 08:01

Jones1220



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!