## 报错
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
]
]
]
]
]
]
]
];