- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这是我第一次使用 Elastica 并从 ElasticSearch 查询数据
对于我来说,作为初学者,我有一个关于如何使用 Elastica 查询下面的代码的问题?:
curl 'http://localhost:9200/myindex/_search?pretty=true' -d '{
"query" : {
"term": {
"click": "true"
} }, "facets" : {
"matches" : {
"terms" : {
"field" : "pubid",
"all_terms" : true,
"size": 200
}
}
}
}'
希望有人能帮我一把。
谢谢,
最佳答案
应该这样做:
// Create a "global" query
$query = new Elastica_Query;
// Create the term query
$term = new Elastica_Query_Term;
$term->setTerm('click', 'true');
// Add term query to "global" query
$query->setQuery($term);
// Create the facet
$facet = new Elastica_Facet_Terms('matches');
$facet->setField('pubid')
->setAllTerms(true)
->setSize(200);
// Add facet to "global" query
$query->addFacet($facet);
// Output query
echo json_encode($query->toArray());
要运行查询,您需要连接到您的 ES 服务器
// Connect to your ES servers
$client = new Elastica_Client(array(
'servers' => array(
array('host' => 'localhost', 'port' => 9200),
array('host' => 'localhost', 'port' => 9201),
array('host' => 'localhost', 'port' => 9202),
array('host' => 'localhost', 'port' => 9203),
array('host' => 'localhost', 'port' => 9204),
),
));
并指定要针对哪个索引和类型运行查询
// Get index
$index = $client->getIndex('myindex');
$type = $index->getType('typename');
现在您可以运行查询了
$type->search($query);
编辑:如果您使用的是命名空间环境和当前版本的 Elastica,请将创建新对象的所有行相应地更改为
$query = new \Elastica\Query;
$facet = new \Elastica\Facet\Terms
等等
关于php - 如何使用 Elastica 进行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13285250/
我将 FOSElasticaBundle 与 symfony2 和 doctrine 2 一起使用。 我无法理解如何从搜索结果中检索实际的学说对象。我的印象是这是默认行为,但我得到了这种结果: obj
我正在使用https://github.com/ruflin/Elastica的“Elastica:elasticsearch PHP客户端”和 创建这样的查询时,无法使用订单“ASC” /“DESC
默认情况下,我的服务器上运行着一个 Elasticsearch,它运行在端口 9200 上,链接是公共(public)的,这意味着任何人都可以在任何地方插入、更新、删除任何形式的内容。我如何让它像 p
我的问题很简单。我想在 Elastica 的一个查询中组合两个过滤器,一个 filter_bool 和一个 filter_range。代码是 public function getAdvancedTw
我有一个带 Compose.io 的 Elasticsearch 集群,但我无法连接 Elastica Client。这是我的配置: $elasticaClient = new \Elasti
我只是不知道如何使用 Elastica 进行自定义查询。我有一个搜索表单来查找产品,用户可以在其中输入名称、选择类别、品牌等。 在我的产品映射中,有一个名为“category_id”的字段,其中包含您
到目前为止,我一直使用Groups批注来序列化和填充我的Elastic搜索索引,并且它仅使用“elastica”组中的字段,并且仅用于fos_elastica.yml中列出的Entities,因此运行
我正在寻找一种使用 Elastica 同时搜索多个索引的方法。 我有一个索引 products 和一个索引 user。 products 包含 {product_id, product_name, p
我正在对使用 FOS Elastica 的存储库进行单元测试,我想知道是否有人知道如何获取查询的字符串版本,而不是数组形式。这是我的存储库方法: /** * Creates quer
这是我第一次使用 Elastica 并从 ElasticSearch 查询数据 对于我来说,作为初学者,我有一个关于如何使用 Elastica 查询下面的代码的问题?: curl 'http://lo
我一直在使用 ElasticSearch 和 Elastica ( http://elastica.io/ ) 整合我们的搜索实现。 目前我无法弄清楚如何执行 count 搜索,正如 ElasticS
我正在尝试让ES QueryString匹配其中包含“和”的搜索词,但是到目前为止我尝试过的一切(尝试使用不同的分析器,tokenziers,过滤器)均无效。用MySQL的话,我想要的是: WHERE
我们有一个symfony应用程序,使用FOS \ ElasticaBundle \ Elastica-Package。一切正常。我们已经使用./app/console fos:elastica:pop
我尝试了很多事情来使用 PHP - Elastica 库 (FosElasticaBundle) 在 ElasticSearch 中执行一个简单的匹配值请求。但是没有运行。你有正确运行这种代码的想法吗
使用 PHP Elastica 库,我想知道检查 Id=1 文档是否存在的最佳方法是什么? 我是这样做的: $docPre = $elasticaType->getDocument(1); if ($
我有一个 Elastic Search 查询: { "query": { "bool": { "must": [ { "match": {"titl
我想使用elastica过滤类别中的多个匹配项: 就像是: (categories.name =“category-1” AND Categories.level = 0)AND(categories
我有 Elastica 库并在我的项目中实现了 ElasticSearch。我想从索引中删除文档。如何使用 elastica 在 elasticsearch 中按 id 删除文档?我尝试了多种解决方案
我目前正在使用FOQElasticaBundle与我的Elasticsearch服务器进行交互,但是我似乎找不到一种基于每个实体上的“ Activity ”标志来限制搜索结果的方法。是否可以通过某种方
我有一个包含许多记录的 SQL 表。当我搜索时,我不想使用所有结果,但我希望它在我想要的 id 中。 我添加了'term ' 并添加了 ' addMust ' 到 boolQuery .但是没有结果。
我是一名优秀的程序员,十分优秀!