1

Is it possible to return the search tokens along with the search results? Not highlighted search results, but the tokens in a separate array field. Docs do not mention this option. I know I can make a separate analyze request, but that's not what I need.

Example of a search query:

{
   "explain": true,
   "query" : {
      "query_string" : {
          "query": "\"General Electric\""
      },
      "default_field": "all"
   }
}

Response:

{
    "took": 108,
    "timed_out": false,
    "_shards": {
        "total": 2,
        "successful": 2,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 1225,
        "max_score": 10.362924,
        "hits": [
            {
                "_shard": "[documents_en_2021-08][0]",
                "_node": "11WLf7tHS_uRNc4YMRYfMg",
                "_index": "documents_en_2021-08",
                "_type": "document",
                "_id": "281973200753421",
                "_score": 10.362924,
                "_source": {...},
                "_explanation": {
                    "value": 10.362924,
                    "description": "sum of:",
                    "details": [
                        {
                            "value": 10.362924,
                            "description": "weight(all:\"gener electr\" in 29284) [PerFieldSimilarity], result of:",
                            "details": [
                                {
                                    "value": 10.362924,
                                    "description": "score(doc=29284,freq=2.0 = phraseFreq=2.0\n), product of:",
                                    "details": [
                                        {
                                            "value": 5.828934,
                                            "description": "idf(), sum of:",
                                            "details": [
                                                {
                                                    "value": 2.2141302,
                                                    "description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
                                                    "details": [
                                                        {
                                                            "value": 125554.0,
                                                            "description": "docFreq",
                                                            "details": []
                                                        },
                                                        {
                                                            "value": 1149255.0,
                                                            "description": "docCount",
                                                            "details": []
                                                        }
                                                    ]
                                                },
                                                {
                                                    "value": 3.614804,
                                                    "description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
                                                    "details": [
                                                        {
                                                            "value": 30940.0,
                                                            "description": "docFreq",
                                                            "details": []
                                                        },
                                                        {
                                                            "value": 1149255.0,
                                                            "description": "docCount",
                                                            "details": []
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "value": 1.7778419,
                                            "description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
                                            "details": [
                                                {
                                                    "value": 2.0,
                                                    "description": "phraseFreq=2.0",
                                                    "details": []
                                                },
                                                {
                                                    "value": 1.2,
                                                    "description": "parameter k1",
                                                    "details": []
                                                },
                                                {
                                                    "value": 0.75,
                                                    "description": "parameter b",
                                                    "details": []
                                                },
                                                {
                                                    "value": 329.31085,
                                                    "description": "avgFieldLength",
                                                    "details": []
                                                },
                                                {
                                                    "value": 64.0,
                                                    "description": "fieldLength",
                                                    "details": []
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        },
                        {
                            "value": 0.0,
                            "description": "match on required clause, product of:",
                            "details": [
                                {
                                    "value": 0.0,
                                    "description": "# clause",
                                    "details": []
                                },
                                {
                                    "value": 1.0,
                                    "description": "DocValuesFieldExistsQuery [field=_primary_term]",
                                    "details": []
                                }
                            ]
                        }
                    ]
                }
            }
         ]
      }
  }

In the explanation part I can see search tokens - "gener" and "electr". My question Is there an option to get these tokens with the search as a plain array like ["gener", "electr"]?

Ken White
  • 123,280
  • 14
  • 225
  • 444
Evgeni Nabokov
  • 2,421
  • 2
  • 32
  • 36

0 Answers0