1. ///////////////////////////////////////////////////////////////////////////
    2. /*
    3. //生成请求对象
    4. //$client = new Elastica\Client($_config);
    5. //生成文档对象
    6. $document = new Elastica\Document();
    7. $id = '23';
    8. $time = time();
    9. $data =array(
    10. 'name'=>'test 叶问 dd ',
    11. 'age'=> '9999',
    12. 'test'=>'just for test ',
    13. 'time'=>$time
    14. );
    15. $typestr = "bfire";
    16. $indexstr = "test_index";//abc
    17. $document->setId($id);
    18. $document->setData($data);
    19. $document->setType($typestr);
    20. $document->setIndex($indexstr);
    21. $arr = array($document);
    22. */
    23. //添加
    24. //$reindex = $client->addDocuments($arr);
    25. //更新
    26. //$reindex = $client->updateDocument($id, $document, $indexstr, $typestr);
    27. //删除
    28. //$reindex = $client->deleteDocuments($arr);
    29. //查询1
    30. //$es_query = new Elastica\Query();
    31. //字段名与属性名
    32. //$term_filter = new Elastica\Filter\Term();
    33. //$term_filter->setTerm('email', 'com');//$term_filter->setTerm('_id', '22');
    34. //$es_query->setFilter($term_filter);
    35. //$es_search = new Elastica\Search($client);
    36. //按库查
    37. //$es_search->addIndex('abc');
    38. //按表查
    39. //$es_search->addType('9999bfire');
    40. //$es_search->setQuery($es_query);
    41. //$res_search = $es_search->search();
    42. //$res = $res_search->getResults();
    43. //按库查
    44. //$es_search->addIndex('test_index');
    45. //只返回fields
    46. //$es_query->setFields();
    47. //比较
    48. //$ra = new Elastica\Filter\Range();
    49. ////$ra->addField('tsn',array('gte' => '1426258760930'));
    50. //$ra->addField('tsn',array('from' => '1426258760925','to' => '1426258760927',));
    51. //$es_query->setPostFilter($ra);
    52. //模糊查询
    53. //$query = new Elastica\Query\Match();
    54. //$query->setField('lv',$lv);
    55. //$query->setFieldFuzziness('lv', 0.7);
    56. //$query->setFieldMinimumShouldMatch('lv', '80%');
    57. // //比较
    58. //$ra = new Elastica\Filter\Range();
    59. ////$ra->addField('tsn',array('gte' => '1426258760930'));
    60. //$ra->addField('tsn',array('from' => $starttime,'to' => $endtime,));
    61. //$es_query->setPostFilter($ra);
    62. /****************************查询总的产品、业务、服务、节点 the start ***************************/
    63. //分组查询包含(四级)
    64. //$query = new Elastica\Query(new Elastica\Query\MatchAll());
    65. //Simple aggregation (based on tags, we get the doc_count for each tag)
    66. //$tagsAggregationindex = new Elastica\Aggregation\Terms('group_by_index');
    67. //$tagsAggregationindex->setField('_index');
    68. //$tagsAggregationtype = new Elastica\Aggregation\Terms('group_by_type');
    69. //$tagsAggregationtype->setField('_type');
    70. //$tagsAggregation = new Elastica\Aggregation\Terms('group_by_cl');
    71. //$tagsAggregation->setField('proj');
    72. //$tagsAggregationiid = new Elastica\Aggregation\Terms('group_by_iid');
    73. //$tagsAggregationiid->setField('iid');
    74. //$tagsAggregation->addAggregation($tagsAggregationiid);
    75. //$tagsAggregationtype->addAggregation($tagsAggregation);
    76. //$tagsAggregationindex->addAggregation($tagsAggregationtype);
    77. //$query->addAggregation($tagsAggregationindex);
    78. //$query->addAggregation($tagsAggregation);
    79. //we don't need the search results, only statistics
    80. //$query->setSize(0);
    81. //$es_search->setQuery($query);
    82. //$res_search = $es_search->search();
    83. //$aggsArr = $res_search->getAggregations();
    84. //echo '<pre>';
    85. //print_r($res_search);exit;
    86. //print_r($aggsArr);exit;
    87. /**************************** 查询总的产品、业务、服务、节点 the end ***************************/
    88. //////////////////////////////////////////////////////////////////////////////////