elasticsearch

## 报错
q: missing authentication token for REST request 
a: 'hosts' => ['http://elastic:changeme@172.17.0.1:9200'],

1. 随机排序


$search = [
    'size' => 20,
    'body' => [
        'query' => [
            'match' => [
                'title' => $_REQUEST['title']
            ]
        ],
        'sort' => [
            '_script' => [
                'script' => 'Math.random()',
                'type' => 'number',
                'order' => 'desc',
            ]
        ]
    ]
];

2. (title=%% or (title=%% or author=%%)) and 200<=time<=300

{
    "from": 0,
    "size": 10,
    "query": {
        "bool": {
            "should": [
                {
                    "match": {
                        "title": {
                            "query": "我不"
                        }
                    }
                },
                {
                    "match_phrase": {
                        "title": {
                            "query": "女儿雄"
                        }
                    }
                },
                {
                    "multi_match": {
                        "query": "邓",
                        "type": "phrase",
                        "fields": [
                            "title",
                            "author"
                        ]
                    }
                }
            ],
            "must": [
                {
                    "range": {
                        "time": {
                            "gte": 200,
                            "lte": 300
                        }
                    }
                }
            ]
        }
    },
    "sort": [
        {
            "time": {
                "order": "desc"
            }
        }
    ]
}

3. filter

{
    "from": 0,
    "size": 10,
    "query": {
        "bool": {
            "should": [
                {
                    "multi_match": {
                        "query": "その声消えないよ",
                        "type": "phrase",
                        "fields": [
                            "title",
                            "author"
                        ]
                    }
                }
            ],
            "filter": {
                "range": {
                    "time": {
                        "gte": 294,
                        "lte": 300
                    }
                }
            }
        }
    },
    "sort": [
        {
            "time": {
                "order": "desc"
            }
        }
    ]
}

4. time>=200 AND year != 2011 AND (author_id NOT IN (36453, 82976, 34205, 87892, 98048, 983482, 89739) OR author = '刘德华') AND title LIKE '%往事%'

# time>=200 AND year != 2011 AND (author_id NOT IN (36453, 82976, 34205, 87892, 98048, 983482, 89739) OR author = '刘德华') AND title LIKE '%往事%'
$search = [
    'body' => [
        'query' => [
            'bool' => [
                'must' => [
                    [
                        'match' => [
                            'title' => $_REQUEST['title']
                        ]
                    ]
                ],
                'should' => [
                    [
                        'terms' => [
                            'author_id' => [36453, 82976, 34205, 87892, 98048, 983482, 89739,]
                        ]
                    ],
                    [
                        'term' => [
                            'author.keyword' => '刘德华'
                        ]
                    ]
                ],
                'minimum_should_match' => 1, // 最小匹配度
                'must_not' => [
                    [
                        'term' => [
                            'year' => '2011'
                        ]
                    ]
                ],
                'filter' => [
                    [
                        'range' => [
                            'time' => [
                                'gte' => 200
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]
];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容