全件表示
{
"query": {
"match_all": {}
}
}
重複排除
{
"collapse": {
"field": "product_name"
},
"query": {
"match_all": {}
}
}
IN句
INを実現するにはtermsを使う。termsはmatchと違って完全一致で検索を行う。
{
"query": {
"terms": {
"product_name": [
"test1",
"test2"
]
}
}
}
曖昧検索
LIKEのような使い方をする場合はこれ。
{
"query": {
"wildcard": {
"user.id": {
"value": "ki*y",
"boost": 1.0,
"rewrite": "constant_score"
}
}
}
}
ANDとかORとか
A AND (B OR C)のような書き方。boolをネストさせることで実現することができる。must/shoud配下には基本クエリを書くことができるので数値A以上の値かつBは完全一致みたいな複雑なクエリも書くことができる。
| 概要 | 説明 |
|---|---|
| must | AND |
| shoud | OR |
| must_not | mustの否定形 |
| filter | mustと似たような使い方だがスコアに関係しない(用途は現在調べ中) |
{
"query": {
"bool": {
"must": [
{
"range": {
"count": {
"gte": 10
}
}
},
{
"bool": {
"should": [
{
"term": {
"product_name": "test"
}
},
{
"term": {
"product_price": 100
}
}
]
}
}
]
}
}
}
minimum_should_matchというパラメータもあって例えばshoudに含まれるべき値の数を絶対値/相対値で指定することも可能。minimum_should_matchを50%とすれば条件が4つのうち2つ満たすもののみ抽出みたいなクエリが書ける。