像ElasticSearch

时间:2015-05-19 06:04:34

标签: php elasticsearch

如何在elasticsearch查询中使用类似查询?

这是我到目前为止所尝试的。

array:3 [
"index" => "users"
"type" => "user"
"body" => array:1 [
"query" => array:1 [
  "bool" => array:1 [
    "should" => array:1 [
      0 => array:3 [
        0 => array:1 [
          "match" => array:1 [
            "fullname" => "Mag*"
          ]
        ]
        1 => array:1 [
          "match" => array:1 [
            "industry_name" => "other"
          ]
        ]
        2 => array:1 [
          "match" => array:1 [
            "active" => "yes"
           ]
         ]
       ]
     ]
     ]
     ]
   ]
   ]

我的搜索json是这样的,

{"1": "Mag","industry_name":"other", "active": "yes"}

在我的索引中,有一个全名“Maggie Wilfred”的记录。 当我运行此查询时,不会返回任何内容。

任何原因?。我觉得问题出在外卡上? "fullname" => "Mag*"

3 个答案:

答案 0 :(得分:1)

应该可行,以这种方式尝试:

    {
        "wildcard" : { "fullname" : "Mag*" }
    }

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wildcard-query.html

答案 1 :(得分:0)

匹配查询不支持https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html

中所述的通配符

您应该尝试使用Wildcardquery。

答案 2 :(得分:0)

{
    "prefix" : { "fullname" : "Mag" }
}