当前位置: 首页>>代码示例>>Java>>正文


Java QueryBuilders.geoShapeQuery方法代码示例

本文整理汇总了Java中org.elasticsearch.index.query.QueryBuilders.geoShapeQuery方法的典型用法代码示例。如果您正苦于以下问题:Java QueryBuilders.geoShapeQuery方法的具体用法?Java QueryBuilders.geoShapeQuery怎么用?Java QueryBuilders.geoShapeQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.index.query.QueryBuilders的用法示例。


在下文中一共展示了QueryBuilders.geoShapeQuery方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testShapeFilterWithRandomGeoCollection

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
public void testShapeFilterWithRandomGeoCollection() throws Exception {
    // Create a random geometry collection.
    GeometryCollectionBuilder gcb = RandomShapeGenerator.createGeometryCollection(random());

    logger.info("Created Random GeometryCollection containing {} shapes", gcb.numShapes());

    client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree")
            .execute().actionGet();

    XContentBuilder docSource = gcb.toXContent(jsonBuilder().startObject().field("location"), null).endObject();
    client().prepareIndex("test", "type", "1").setSource(docSource).setRefreshPolicy(IMMEDIATE).get();

    ShapeBuilder filterShape = (gcb.getShapeAt(randomIntBetween(0, gcb.numShapes() - 1)));

    GeoShapeQueryBuilder filter = QueryBuilders.geoShapeQuery("location", filterShape);
    filter.relation(ShapeRelation.INTERSECTS);
    SearchResponse result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
            .setPostFilter(filter).get();
    assertSearchResponse(result);
    assertHitCount(result, 1);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:GeoShapeQueryTests.java

示例2: main

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
public static void main(String[] args) {
   /* QueryBuilder qb1 = QueryBuilders.matchQuery("a","b");
    System.out.println(qb1.toString());*/
    String json="{\"query\":{\"match_all\":{}},\"filter\":{\"geo_shape\":{\"geometry\":{\"relation\":\"CONTAINS\",\"shape\":{\"coordinates\":[116.402257,39.914548],\"type\":\"point\"}}}}}";
    QueryBuilder qb= QueryBuilders.matchAllQuery();
    //System.out.println(qb.toString());
    SearchSourceBuilder searchSourceBuilder=new SearchSourceBuilder();
    searchSourceBuilder.query(qb);
   // System.out.println(searchSourceBuilder.toString());
    ShapeBuilder shapeBuilder= ShapeBuilder.newPoint(new Coordinate(116.402257,39.914548));
    QueryBuilder qb2= QueryBuilders.geoShapeQuery("geometry",shapeBuilder, ShapeRelation.CONTAINS);
    System.out.println(qb2.toString());

    //searchSourceBuilder.postFilter(qb2);
    QueryBuilder qb3= QueryBuilders.boolQuery().must(qb).filter(qb2);
    searchSourceBuilder.query(qb3);
    System.out.println(qb3.toString());
    System.out.println(searchSourceBuilder.toString());
    QueryBuilder qb4= QueryBuilders.boolQuery().must(qb).must(qb2);
    System.out.println(qb4.toString());


    SortBuilder sort= SortBuilders.geoDistanceSort("pin.location") .point(40, -70).
            unit(DistanceUnit.fromString(DistanceUnit.KILOMETERS.toString())).order(SortOrder.DESC);
  /*  QueryBuilder qb5 = QueryBuilders.geoDistanceQuery("pin.location")
            .point(40, -70)
            .distance(400,  DistanceUnit.fromString(DistanceUnit.KILOMETERS.toString()))
            .geoDistance(GeoDistance.ARC);
             System.out.println(qb5.toString());
            */
    searchSourceBuilder.sort(sort);
    System.out.println(searchSourceBuilder.toString());
    //QueryBuilder qb3=QueryBuilders.filteredQuery(null,qb2);
    //QueryBuilder qb4=QueryBuilders.filteredQuery(qb,qb2);
    //searchSourceBuilder.query(qb3.toString());
   // searchSourceBuilder.query(qb4);
   // System.out.println(qb4.toString());
    //System.out.println(searchSourceBuilder.toString());

    // System.out.println(qb.toString());
   /* QueryBuilder qb2 = QueryBuilders.geoBoundingBoxQuery("pin.location")
            .topLeft(40.73, -74.1)
            .bottomRight(40.717, -73.99);
    //String  strstr= JSON.toJSONString(qb2);
    System.out.println(qb2.toString());
    System.out.println("1111111");*/
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:48,代码来源:Test.java

示例3: t_queryByEsQueryDo2

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
@org.junit.Test
public void t_queryByEsQueryDo2()throws Exception {
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    QueryBuilder qb = QueryBuilders.matchAllQuery();
    searchSourceBuilder.query(qb);
    ShapeBuilder shapeBuilder = ShapeBuilder.newPoint(new Coordinate(116.402257, 39.914548));
    QueryBuilder qb2 = QueryBuilders.geoShapeQuery("geometry", shapeBuilder, ShapeRelation.CONTAINS);

    QueryBuilder qb3 = QueryBuilders.boolQuery().must(qb).filter(qb2);
    searchSourceBuilder.query(qb3);
   iEsQueryDao.query(searchSourceBuilder,"twitter","user","user2");
    /*logger.info(JSON.toJSONString(es));
    Assert.assertNotEquals("1", es.getStatus());*/
}
 
开发者ID:AsuraTeam,项目名称:asura,代码行数:15,代码来源:T_IEsQueryDao.java

示例4: testShapeFilterWithDefinedGeoCollection

import org.elasticsearch.index.query.QueryBuilders; //导入方法依赖的package包/类
public void testShapeFilterWithDefinedGeoCollection() throws Exception {
    createIndex("shapes");
    client().admin().indices().prepareCreate("test").addMapping("type", "location", "type=geo_shape,tree=quadtree")
            .execute().actionGet();

    XContentBuilder docSource = jsonBuilder().startObject().startObject("location")
            .field("type", "geometrycollection")
            .startArray("geometries")
            .startObject()
            .field("type", "point")
            .startArray("coordinates")
            .value(100.0).value(0.0)
            .endArray()
            .endObject()
            .startObject()
            .field("type", "linestring")
            .startArray("coordinates")
            .startArray()
            .value(101.0).value(0.0)
            .endArray()
            .startArray()
            .value(102.0).value(1.0)
            .endArray()
            .endArray()
            .endObject()
            .endArray()
            .endObject().endObject();
    client().prepareIndex("test", "type", "1")
            .setSource(docSource).setRefreshPolicy(IMMEDIATE).get();

    GeoShapeQueryBuilder filter = QueryBuilders.geoShapeQuery(
            "location",
            ShapeBuilders.newGeometryCollection()
                    .polygon(
                            ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(99.0, -1.0).coordinate(99.0, 3.0).coordinate(103.0, 3.0).coordinate(103.0, -1.0)
                                    .coordinate(99.0, -1.0)))).relation(ShapeRelation.INTERSECTS);
    SearchResponse result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
            .setPostFilter(filter).get();
    assertSearchResponse(result);
    assertHitCount(result, 1);
    filter = QueryBuilders.geoShapeQuery(
            "location",
            ShapeBuilders.newGeometryCollection().polygon(
                    ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(199.0, -11.0).coordinate(199.0, 13.0).coordinate(193.0, 13.0).coordinate(193.0, -11.0)
                            .coordinate(199.0, -11.0)))).relation(ShapeRelation.INTERSECTS);
    result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
            .setPostFilter(filter).get();
    assertSearchResponse(result);
    assertHitCount(result, 0);
    filter = QueryBuilders.geoShapeQuery("location", ShapeBuilders.newGeometryCollection()
            .polygon(ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(99.0, -1.0).coordinate(99.0, 3.0).coordinate(103.0, 3.0).coordinate(103.0, -1.0).coordinate(99.0, -1.0)))
                    .polygon(
                            ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinate(199.0, -11.0).coordinate(199.0, 13.0).coordinate(193.0, 13.0).coordinate(193.0, -11.0)
                                    .coordinate(199.0, -11.0)))).relation(ShapeRelation.INTERSECTS);
    result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
            .setPostFilter(filter).get();
    assertSearchResponse(result);
    assertHitCount(result, 1);
    // no shape
    filter = QueryBuilders.geoShapeQuery("location", ShapeBuilders.newGeometryCollection());
    result = client().prepareSearch("test").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
            .setPostFilter(filter).get();
    assertSearchResponse(result);
    assertHitCount(result, 0);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:66,代码来源:GeoShapeQueryTests.java


注:本文中的org.elasticsearch.index.query.QueryBuilders.geoShapeQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。