Skip to content

Instantly share code, notes, and snippets.

@khalidabuhakmeh
Created January 20, 2017 17:02
Show Gist options
  • Save khalidabuhakmeh/68dfe2405c33fd4cfee9d2030e8e2f18 to your computer and use it in GitHub Desktop.
Save khalidabuhakmeh/68dfe2405c33fd4cfee9d2030e8e2f18 to your computer and use it in GitHub Desktop.

Note that Title in the result ends with a ), but in the highlight result it is missing. What going on?

Mapping

{
  "content-search-sites-20-01-2017-16-12-22": {
    "mappings": {
      "searchindexdocument": {
        "properties": {
          "Authors": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "Categories": {
            "type": "keyword"
          },
          "Content": {
            "type": "text"
          },
          "Excerpt": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "Id": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "Private": {
            "type": "boolean"
          },
          "PublishedDate": {
            "type": "date"
          },
          "Site": {
            "type": "keyword"
          },
          "Tags": {
            "type": "keyword"
          },
          "Title": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "Url": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

Search

GET content-search-sites/_search
{
  "size": 1, 
  "_source": "Title", 
    "query" : {
        "multi_match": { 
          "query": "Test", 
          "fields": [ "Title^4", "Tags^2", "Content", "Authors"]
        }
    },
    "highlight" : {
        "pre_tags": ["<mark>"],
        "post_tags": ["</mark>"], 
        "fields" : {
            "Content" : {
                "fragment_size" : 150,
                "number_of_fragments" : 3,
                "no_match_size": 150
            },
            "Title": {
              "fragment_size" : 150,
                "number_of_fragments" : 3,
                "no_match_size": 150
            }
        }
    }
}

Result

{
  "took": 15,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 8,
    "max_score": 3.0916476,
    "hits": [
      {
        "_index": "content-search-sites-20-01-2017-16-12-22",
        "_type": "searchindexdocument",
        "_id": "https-rimdev-io-under-the-decision-tree-12-1482476400",
        "_score": 3.0916476,
        "_source": {
          "Title": "Under the Decision Tree (#12)"
        },
        "highlight": {
          "Content": [
            " will help businesses fight hacker fraternisation, predict insider threats Google researchers develop a <mark>test</mark> for machine learning bias Microsoft Launches",
            " 3Pillar Global bets big on machine learning Discrimination by algorithm: scientists devise <mark>test</mark> to detect AI bias The Conundrum of Machine Learning and"
          ],
          "Title": [
            "Under the Decision Tree (#12"
          ]
        }
      }
    ]
  }
}
@khalidabuhakmeh
Copy link
Author

This was all done via Kibana, so NEST was not in the middle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment