Elasticsearch query time boosting produces result in inadequate order

后端 未结 1 1980
死守一世寂寞
死守一世寂寞 2021-01-16 16:37

The ES search result for the given search keyword one two three seems to be wrong after applying boost feature per keyword. Please help me modifyin

1条回答
  •  被撕碎了的回忆
    2021-01-16 17:10

    # Index some test data
    curl -XPUT "localhost:9200/test/doc/1" -d '{"title": "one"}'
    curl -XPUT "localhost:9200/test/doc/2" -d '{"title": "two"}'
    curl -XPUT "localhost:9200/test/doc/3" -d '{"title": "three"}'
    curl -XPUT "localhost:9200/test/doc/4" -d '{"title": "one two"}'
    curl -XPUT "localhost:9200/test/doc/5" -d '{"title": "one three"}'
    curl -XPUT "localhost:9200/test/doc/6" -d '{"title": "one two three"}'
    curl -XPUT "localhost:9200/test/doc/7" -d '{"title": "two three"}'
    curl -XPUT "localhost:9200/test/doc/8" -d '{"title": "none"}'
    curl -XPUT "localhost:9200/test/doc/9" -d '{"title": "one abc"}'
    curl -XPUT "localhost:9200/test/doc/10" -d '{"title": "two abc"}'
    curl -XPUT "localhost:9200/test/doc/11" -d '{"title": "three abc"}'
    curl -XPUT "localhost:9200/test/doc/12" -d '{"title": "one two abc"}'
    curl -XPUT "localhost:9200/test/doc/13" -d '{"title": "one two three abc"}'
    curl -XPUT "localhost:9200/test/doc/14" -d '{"title": "two three abc"}'
    # Make test data available for search
    curl -XPOST "localhost:9200/test/_refresh?pretty"
    # Search using function score
    curl -XPOST "localhost:9200/test/doc/_search?pretty" -d'{
        "query": {
            "function_score": {
                "query": {
                    "match": {
                        "title": "one two three"
                    }
                },
                "functions": [
                    {
                        "filter": {
                            "query": {
                                "match": {
                                    "title": "one"
                                }
                            }
                        },
                        "weight": 1
                    },
                    {
                        "filter": {
                            "query": {
                                "match": {
                                    "title": "two"
                                }
                            }
                        },
                        "weight": 2
                    },
                    {
                        "filter": {
                            "query": {
                                "match": {
                                    "title": "three"
                                }
                            }
                        },
                        "weight": 3
                    }
                ],
                "score_mode": "sum",
                "boost_mode": "replace"
            }
        },
        "sort": [
            {
                "_score": {
                    "order": "desc"
                }
            }
        ],
        "from": "0",
        "size": "100"
    }'
    

    0 讨论(0)
提交回复
热议问题