filter spell suggester result by weight in elasticsearch

Viewed 134

First, I indexed some docs using the following mapping:

{
    "test_index": {
        "mappings": {
            "dynamic": "strict",
            "properties": {
                "content_completion": {
                    "type": "completion",
                    "analyzer": "hashtag_analyzer",
                    "preserve_separators": true,
                    "preserve_position_increments": true,
                    "max_input_length": 50,
                    "fields": {
                        "content": {
                            "type": "text",
                            "analyzer": "shingle_analyzer"
                        }
                    }
                }
            }
        }
    }
}

Then I put some docs in it using:

    PUT test/_doc/1?refresh
{
 "content_completion" : {
  "input": "nobel",
  "weight" : 5
 },
 "content_completion" : {
  "input": "nobel marathon",
  "weight" : 5
 },
 "content_completion" : {
  "input": "nobel is good",
  "weight" : 5
 },
 "content_completion" : {
  "input": "nobel is life",
  "weight" : 5
 },
 "content_completion" : {
  "input": "no bei",
  "weight" : 1000000000
  }
 }

(There is no duplicate doc in the index.) I have the following spell-suggest query:

{
    "suggest": {
        "text": "nobei",
        "spell-checker-suggest": {
            "phrase": {
                "field": "content_completion.content",
                "gram_size": 2,
                "size": 10,
                "analyzer": "hashtag_analyzer",
                "real_word_error_likelihood": 0.95,
                "direct_generator": [
                        {
                        "field": "content_completion.content",
                        "min_doc_freq": "1",
                        "suggest_mode": "missing",
                        "prefix_length": 0,
                        "sort": "score",
                        "min_word_length": 2
                        }
                    ],
                "highlight": {
                    "pre_tag": "<em>",
                    "post_tag": "</em>"
                }
            }
        }
    }
}

and got a result like this:

   {
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "suggest": {
    "spell-checker-suggest_1": [
      {
        "text": "nobei",
        "offset": 0,
        "length": 5,
        "options": [
          {
            "text": "nobel",
            "highlighted": "<em>nobel</em>",
            "score": 0.45925426
          }
        ]
      }
    ]
  }
}

elsaticsearch is not using weight for scoring and just apply the frequency. What I want is to do one of items below if possible:

  • make elsaticsearch use weight for scoring and not frequency
  • show the sum of weights which the term has appeared on them, inside options json object.
  • modify score such that it computes using weight and frequency
0 Answers
Related