Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting no term vector result from elasticsearch?

enter image description here

I'm following https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html however cannot get the expected result. Which part did I do wrong?

The format of the documents are:

PUT integrity
{
  "mappings": {
    "body": {
      "properties": {
        "label": {
          "type": "keyword",
          "index": "not_analyzed",
          "store": true
        },
        "body": {
          "type": "text",
          "store": true
        }
      }
    }
  }
}
like image 559
firstprayer Avatar asked Mar 18 '26 14:03

firstprayer


1 Answers

The default mapping of the _all field doesn't include storing the term vectors:

    "_all": {
      "full_name": "_all",
      "mapping": {
        "_all": {
          "enabled": true,
          "store": false,
          "store_term_vectors": false,
          "store_term_vector_offsets": false,
          "store_term_vector_positions": false,
          "store_term_vector_payloads": false,
          "norms": true,
          "analyzer": "default",
          "similarity": "BM25"
        }
      }
    }

and, also, it seems the _all field is a bit special and Elasticsearch doesn't compute the vectors on the fly.

Your only option for _all is to enable term vectors on it:

PUT integrity
{
  "mappings": {
    "body": {
      "_all": {
        "term_vector": "with_positions_offsets"
      }, 
      "properties": {
        "label": {
          "type": "keyword",
          "index": "not_analyzed",
          "store": true
        },
        "body": {
          "type": "text",
          "store": true
        }
      }
    }
  }
}
like image 61
Andrei Stefan Avatar answered Mar 24 '26 23:03

Andrei Stefan



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!