0
votes

I am trying to build a full-text search query over thousand of documents with dynamic structure.

But the highlight method works only for specifically named fields.

If I want to use search over _all or _source it doesn't show any hihlighted result.

I already tried many various and tried to "googling" but with no success.

Basic query:

POST tracking*/_search
{
    "query": {
    "query_string": {
      "query": "ci1483967534008.6100622@czcholsint372_te"
    }
  },
  "highlight": {
    "require_field_match": false
  }
}

will return:

  "hits": {
    "total": 8,
    "max_score": 13.482396,
    "hits": [
      {
        "_index": "tracking-2017.01.09",
        "_type": "cyclone",
        "_id": "Cyclone1-UAT-ci1483967534008.6100622@czcholsint372_te-Messaging.Message.MessageUnpackaged.Request",
        "_score": 13.482396,
        "_source": {
        ... truncated ...
          "received": "2017-01-09T13:12:14.008Z",
          "tags": [],
          "@timestamp": "2017-01-09T13:12:14.008Z",
          "size": "3169",
          "pairing": " ci1483967534008.6100622@czcholsint372_te <[email protected]> ErpExJets_RDC1_ProcessPurchaseOrder_9.4.1_20170109131207169 ErpExJets_RDC1_ProcessPurchaseOrder_9.4.1_20170109131207169",
        }
      },

but no highlight even if the searched string is in the pairing field.

Is it possible at all?

Thanks Reddy

1

1 Answers

0
votes

Elastic doumentation mentions this as Note - "in order to perform highlighting, the actual content of the field is required. If the field in question is stored (has store set to true in the mapping) it will be used, otherwise, the actual _source will be loaded and the relevant field will be extracted from it."

So unless you have _all set to true use the following query.

{
    "query": {
        "query_string": {
            "query": "ci1483967534008.6100622@czcholsint372_te"
        }
    },
    "highlight": {
        "require_field_match": false,
        "fields": {
            "pairing": {}
        }
    }
}

If you have _all set to true for source docuemnt use the following

{
    "query": {
        "query_string": {
            "query": "ci1483967534008.6100622@czcholsint372_te"
        }
    },
    "highlight": {
        "require_field_match": false,
        "fields": {
            "_all": {}
        }
    }
}

Hope this helps.