spring-data-elasticsearch 다중 플러그인 대상 조회

3092 단어 ElasticSearch
데이터 저장소 형식:
{
    "_index":"earth",
    "_type":"earth2",
    "_id":"n-3",
    "_version":1,
    "_score":1,
    "_source":{
        "jid":"n-3",
        "udateTime":"2018-01-30 14:10:04",
        "orderItem":[
            {
                "orderType":"RO",
                "orderDate":"20170708",
                "orderItems":[
                    {
                        "skuNo":"154018",
                        "stockSite":"0001",
                        "costOfSale":108.9
                    }
                ]
            }
        ]
    }
}

질의 문:
{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "orderItem.orderItems",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "orderItem.orderItems.skuNo": "154018"
                    }
                  },
                  {
                    "match": {
                      "orderItem.orderItems.stockSite": "0001"
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "nested": {
            "path": "orderItem",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "orderItem.orderType": "RO"
                    }
                  },
                  {
                    "match": {
                      "orderItem.orderDate": "20170708"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

spring-data-elasticsearch 및 java API 질의로 변환하기
		QueryBuilder orderItemsQuery = QueryBuilders.nestedQuery("orderItem.orderItems",
				QueryBuilders.boolQuery()
						.must(QueryBuilders.matchQuery("orderItem.orderItems.stockSite", "0001"))
						.must(QueryBuilders.matchQuery("orderItem.orderItems.skuNo", "154018")),
				ScoreMode.Total);

		QueryBuilder orderQuery = QueryBuilders.nestedQuery("orderItem",
				QueryBuilders.boolQuery()
						.must(QueryBuilders.matchQuery("orderItem.orderType", "RO"))
						.must(QueryBuilders.matchQuery("orderItem.orderDate", "20170708")),
				ScoreMode.Total);

		QueryBuilder queryBuilder = QueryBuilders.boolQuery().must(orderQuery).must(orderItemsQuery);

		Iterable it = orderRepository.search(queryBuilder);
		List list = Lists.newArrayList(it);
		System.out.println(list);
		

좋은 웹페이지 즐겨찾기