26/08/2017 - ELASTICSEARCH
Bu örneğimizde elasticsearch ile SQL LIKE
benzeri sorgu örnekleri yaratacağız. Daha fazla bilgi için Partial Matching sayfasını okuyun.
Wildcard seçeneği filtered
sorgularında kullanılamaz.
"name": {
"type": "string",
"index": "not_analyzed" # Not a full-text search
}
SELECT * FROM products WHERE name LIKE 'Product1*'
{
"query": {
"prefix": {
"name.raw": "Product1"
}
}
}
{
"query": {
"wildcard": {
"name.raw": "Product1*"
}
}
}
{
"query": {
"regexp": {
"name.raw": "Product1.*"
}
}
}
{
"query": {
"bool": {
"must": {
"prefix": {
"name.raw": "Product1"
}
}
}
}
}
{
"query": {
"bool": {
"must": [
{
"prefix": {
"name.raw": "Product1"
}
}
]
}
}
}
{
"query": {
"bool": {
"must": {
"wildcard": {
"name.raw": "Product1*"
}
}
}
}
}
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"name.raw": "Product1*"
}
}
]
}
}
}
{
"query": {
"bool": {
"must": {
"regexp": {
"name.raw": "Product1.*"
}
}
}
}
}
{
"query": {
"bool": {
"must": [
{
"regexp": {
"name.raw": "Product1.*"
}
}
]
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": {
"prefix": {
"name.raw": "Product1"
}
}
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"prefix": {
"name.raw": "Product1"
}
}
]
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": {
"regexp": {
"name.raw": "Product1.*"
}
}
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"regexp": {
"name.raw": "Product1.*"
}
}
]
}
}
}
}
}
SELECT * FROM products WHERE name LIKE 'Product1*' AND colour LIKE 'P*'
{
"query": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"colour": "P"
}
}
]
}
}
}
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"name": "Product1*"
}
},
{
"wildcard": {
"colour": "P*"
}
}
]
}
}
}
{
"query": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "Shop7.*"
}
}
]
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"colour": "P"
}
}
]
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "P.*"
}
}
]
}
}
}
}
}
SELECT * FROM products WHERE name LIKE 'Product1*' AND colour LIKE 'P*' AND year = 2000
{
"query": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"colour": "P"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"name": "Product1*"
}
},
{
"wildcard": {
"colour": "P*"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
{
"query": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "Shop7.*"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"prefix": {
"name": "Product1"
}
},
{
"prefix": {
"shops.name": "Shop7"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": [
{
"regexp": {
"name": "Product1.*"
}
},
{
"regexp": {
"colour": "P.*"
}
},
{
"term": {
"year": 2000
}
}
]
}
}
}
}
}