美文网首页
013 算分优化&一致性随机函数&suggestions

013 算分优化&一致性随机函数&suggestions

作者: zhu733756 | 来源:发表于2020-03-24 18:12 被阅读0次

DELETE blogs

PUT /blogs/_doc/1

{

  "title":  "About popularity",

  "content": "In this post we will talk about...",

  "votes":  0

}

PUT /blogs/_doc/2

{

  "title":  "About popularity",

  "content": "In this post we will talk about...",

  "votes":  100

}

PUT /blogs/_doc/3

{

  "title":  "About popularity",

  "content": "In this post we will talk about...",

  "votes":  1000000

}

#算分优化

POST /blogs/_search

{

  "query": {

    "function_score": {

      "query": {

        "multi_match": {

          "query": "popularity",

          "fields": [

            "title",

            "content"

          ]

        }

      },

      "field_value_factor": {

        "field": "votes",

        "modifier": "log2p",

        "factor": 0.2

      },

      "boost_mode": "multiply",

      "max_boost": 100

    }

  }

}

#一致性随机函数,返回的排名始终一致,可以对一类用户使用

POST /blogs/_search

{

  "query": {

    "function_score": {

      "random_score":{

        "seed": 3141

      }

    }

  }

}

# term suggestion & phrase suggestion

DELETE articles

PUT articles

{

  "mappings": {

    "properties": {

      "title_completion":{

        "type": "completion"

      }

    }

  }

}

POST articles/_bulk

{ "index" : { } }

{ "title_completion": "lucene is very cool"}

{ "index" : { } }

{ "title_completion": "Elasticsearch builds on top of lucene"}

{ "index" : { } }

{ "title_completion": "Elasticsearch rocks"}

{ "index" : { } }

{ "title_completion": "elastic is the company behind ELK stack"}

{ "index" : { } }

{ "title_completion": "Elk stack rocks"}

{ "index" : {} }

POST articles/_search?pretty

{

  "size": 0,

  "suggest": {

    "article-suggester": {

      "prefix": "elk ",

      "completion": {

        "field": "title_completion"

      }

    }

  }

}

DELETE articles

POST articles/_bulk

{ "index" : { } }

{ "body": "lucene is very cool"}

{ "index" : { } }

{ "body": "Elasticsearch builds on top of lucene"}

{ "index" : { } }

{ "body": "Elasticsearch rocks"}

{ "index" : { } }

{ "body": "elastic is the company behind ELK stack"}

{ "index" : { } }

{ "body": "Elk stack rocks"}

{ "index" : {} }

{  "body": "elasticsearch is rock solid"}

POST /articles/_search

{

  "size": 1,

  "query": {

    "match": {

      "body": "lucen rock"

    }

  },

  "suggest": {

    "term-suggestion": {

      "text": "lucen rock",

      "term": {

        "suggest_mode": "always",

        "field": "body"

      }

    }

  }

}

POST /articles/_search

{

  "suggest": {

    "my_suggestion": {

      "text": "lucen rock",

      "phrase":{

        "field": "body",

        "max_errors":2,

        "confidence":1,

        "direct_generator":[{

          "field":"body",

          "suggest_mode":"always"

        }],

        "highlight": {

          "pre_tag": "<em>",

          "post_tag": "</em>"

        }

      }

    }

  }

}

相关文章

网友评论

      本文标题:013 算分优化&一致性随机函数&suggestions

      本文链接:https://www.haomeiwen.com/subject/pyrayhtx.html