您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Elasticsearch查询时间提升导致顺序不足的结果

Elasticsearch查询时间提升导致顺序不足的结果

# 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"
}'
其他 2022/1/1 18:15:31 有660人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶