我对弹性搜索相对较新,并且我尝试在php中使用以下查询执行搜索,但是我收到错误。
$query = array(
'query' => array(
'query_string' => array(
'query' => "(name_en:cook)^2 OR (name_en:door) AND (_id:11)",
)
),
'suggest' => array(
'text' => "unganda",
'term'=>array(
"field"=> "name_en",
"max_edits"=> 2,
"sort"=> "score",
"suggest_mode"=>"missing",
"prefix_length"=> 0,
"min_word_length"=> 2
)
)
);
$response = $client->request($path, \Elastica\Request::GET, $query);
$responseArray = $response->getData();
// Loop through the results
return $responseArray;
diE();
这是正确的做法吗?有人能告诉我怎么写这个。我正在关注this example。
以下是整个错误:
( ! ) Fatal error: Uncaught exception 'Elastica\Exception\ResponseException' with message
'SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
shardFailures {[NBYNTLSbT1iIRv98Oxvbmw][shops][3]:
SearchParseException[[shops][3]:
query[(
(_all:name_en _all:uganda)^2.0)
(_all:name_en _all:grocery_shop)],from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"query_string": {
"query":"(name_en=>uganda)^2 OR (name_en=>grocery_shop)"
}
},
"suggest": {
"text": "grocery_shop",
"term": {
"field": "name_en"
}
}
}]]];
nested: ElasticsearchIllegalArgumentException[[suggest] does not support [field]]; }{[NBYNTLSbT1iIRv98Oxvbmw][shops][4]:
SearchParseException[[shops][4]:
query[(
(_all:name_en _all:uganda)^2.0)
(_all:name_en _all:grocery_shop)],from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"query_string": {
"query":"(name_en=>uganda)^2 OR (name_en=>grocery_shop)"
}
},
"suggest": {
"text": "grocery_shop",
"term": {
"field": "name_en"
}
}
}]]];
nested: Elasticsea in C:\wamp\www\infomoby\vendor\ruflin\elastica\lib\Elastica\Transport\Http.php on line 146
( ! ) Elastica\Exception\ResponseException:
SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
shardFailures {[NBYNTLSbT1iIRv98Oxvbmw][shops][3]:
SearchParseException[[shops][3]:
query[(
(_all:name_en _all:uganda)^2.0)
(_all:name_en _all:grocery_shop)],from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"query_string": {
"query":"(name_en=>uganda)^2 OR (name_en=>grocery_shop)"
}
},
"suggest": {
"text": "grocery_shop",
"term": {
"field": "name_en"
}
}
}]]];
nested: ElasticsearchIllegalArgumentException[[suggest] does not support [field]]; }{[NBYNTLSbT1iIRv98Oxvbmw][shops][4]:
SearchParseException[[shops][4]:
query[(
(_all:name_en _all:uganda)^2.0)
(_all:name_en _all:grocery_shop)],from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"query_string": {
"query":"(name_en=>uganda)^2 OR (name_en=>grocery_shop)"
}
},
"suggest": {
"text": "grocery_shop",
"term": {
"field": "name_en"
}
}
}]]];
nested: ElasticsearchIllegalArgumentException[[suggest] does not support [field]]; }{[NBYNTLSbT1iIRv98Oxvbmw][shops][1]:
SearchParseException[[shops][1]:
query[(
(_all:name_en _all:uganda)^2.0)
(_all:name_en _all:grocery_shop)],from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"query_string": {
"query":"(name_en=>uganda)^2 OR (name_en=>grocery_shop)"
}
},
"suggest": {
"text": "grocery_shop",
"term": {
"field": "name_en"
}
}
}]]];
nested: ElasticsearchIllegalArgumentException[[suggest] does not support [field]]; }{[NBYNTLSbT1iIRv98Oxvbmw][shops][2]:
SearchParseException[[shops][2]:
query[(
(_all:name_en _all:uganda)^2.0)
(_all:name_en _all:grocery_shop)],from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"query_string": {
"query":"(name_en=>uganda)^2 OR (name_en=>grocery_shop)"
}
},
"suggest": {
"text": "grocery_shop",
"term": {
"field": "name_en"
}
}
}]]];
nested: ElasticsearchIllegalArgumentException[[suggest] does not support [field]]; }{[NBYNTLSbT1iIRv98Oxvbmw][shops][0]:
SearchParseException[[shops][0]:
query[(
(_all:name_en _all:uganda)^2.0)
(_all:name_en _all:grocery_shop)],from[-1],size[-1]:
Parse Failure [Failed to parse source [
{
"query": {
"query_string": {
"query":"(name_en=>uganda)^2 OR (name_en=>grocery_shop)"
}
},
"suggest": {
"text": "grocery_shop",
"term": {
"field": "name_en"
}
}
}]]];
nested: ElasticsearchIllegalArgumentException[[suggest] does not support [field]]; }] in C:\wamp\www\shops_site\vendor\ruflin\elastica\lib\Elastica\Transport\Http.php on line 146
答案 0 :(得分:0)
我最终恢复使用基于curl的查询与php,它就像一个魅力。用户bool过滤器的秘密必须和应该选项嵌套模糊这样匹配查询