

def test_function_score_from_dict():
    d = {
        'function_score': {
            'filter': {
                'term': {
                    'tags': 'python',
                },
            },
            'functions': [{
                'filter': {
                    'terms': {
                        'tags': 'python',
                    },
                },
                'script_score': {
                    'script': "doc['comment_count'] * _score",
                },
            }, {
                'boost_factor': 6,
            }],
        },
    }
    q = query.Q(d)
    assert isinstance(q, query.FunctionScore)
    assert isinstance(q.filter, query.Term)
    assert (len(q.functions) == 2)
    sf = q.functions[0]
    assert isinstance(sf, function.ScriptScore)
    assert isinstance(sf.filter, query.Terms)
    sf = q.functions[1]
    assert isinstance(sf, function.BoostFactor)
    assert (6 == sf.value)
    assert ({
        'boost_factor': 6,
    } == sf.to_dict())

dataset/ETHPy150Open elastic/elasticsearch-dsl-py/test_elasticsearch_dsl/test_query.py test_function_score_from_dict/original