Skip to content

Instantly share code, notes, and snippets.

@marczhermo
Created May 2, 2018 14:59
Show Gist options
  • Save marczhermo/6e3e36fe1514846a9b07a708c35b5fb8 to your computer and use it in GitHub Desktop.
Save marczhermo/6e3e36fe1514846a9b07a708c35b5fb8 to your computer and use it in GitHub Desktop.
ElasticSearch
GET _search
"query": {
"match": {
"name": {
"query": "Vacuummm",
"fuzziness": 2,
"prefix_length": 1
}
}
}
$query = [
'index' => $indexName,
'type' => $indexName,
'from' => $pageNumber,
'size' => $pageLength,
'body' => [
'query' => [
'bool' => [
'must' => [
[
'query_string' => [
'query' => empty($term) ? '*' : $term,
'analyze_wildcard' => true,
'default_field' => '*'
]
],
[
'bool' => [
'should' => [
['match_phrase' => [
'PriceRange' => ['query' => '50 - 100']
]
],
['match_phrase' => [
'PriceRange' => ['query' => '100 - 200']
]
]
],
'minimum_should_match' => 1
]
],
[
'match_phrase' => [
'Brand' => ['query' => 'Acer']
]
],
[
'match_phrase' => [
'Categories' => ['query' => 'Monitors']
]
],
],
'filter' => [
'bool' => [
'must' => [
[
'range' => [
'Price' => ['gt' => 120, 'lt' => 200]
]
],
[
'range' => [
'Price' => ['lt' => 300]
]
],
]
]
]
],
],
],
];
fwrite(STDERR, print_r([$this], true));
GET _search
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "monitor",
"analyze_wildcard": true,
"default_field": "*"
}
},
{
"match_phrase": {
"Brand": {
"query": "Acer"
}
}
},
{
"bool": {
"should": [
{
"match_phrase": {
"PriceRange": "50 - 100"
}
},
{
"match_phrase": {
"PriceRange": "100 - 200"
}
}
],
"minimum_should_match": 1
}
}
],
"filter": {
"bool": {
"must": [
{
"range": {
"Price": {
"gt": 120,
"lt": 150
}
}
},
{
"range": {
"Price": {
"lt": 300
}
}
}
]
}
},
"should": [],
"must_not": []
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment