Created
May 2, 2018 14:59
-
-
Save marczhermo/6e3e36fe1514846a9b07a708c35b5fb8 to your computer and use it in GitHub Desktop.
ElasticSearch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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