ElasticSearchIndex implements IndexProvider { @Override public List<String> query(IndexQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException { SearchRequestBuilder srb = client.prepareSearch(indexName); srb.setTypes(query.getStore()); srb.setQuery(QueryBuilders.matchAllQuery()); srb.setPostFilter(getFilter(query.getCondition(),informations.get(query.getStore()))); if (!query.getOrder().isEmpty()) { List<IndexQuery.OrderEntry> orders = query.getOrder(); for (int i = 0; i < orders.size(); i++) { IndexQuery.OrderEntry orderEntry = orders.get(i); FieldSortBuilder fsb = new FieldSortBuilder(orders.get(i).getKey()) .order(orderEntry.getOrder() == Order.ASC ? SortOrder.ASC : SortOrder.DESC); if (useDeprecatedIgnoreUnmapped) { fsb.ignoreUnmapped(true); } else { Class<?> datatype = orderEntry.getDatatype(); fsb.unmappedType(convertToEsDataType(datatype)); } srb.addSort(fsb); } } srb.setFrom(0); if (query.hasLimit()) srb.setSize(query.getLimit()); else srb.setSize(maxResultsSize); srb.setNoFields(); SearchResponse response = srb.execute().actionGet(); log.debug("Executed query [{}] in {} ms", query.getCondition(), response.getTookInMillis()); SearchHits hits = response.getHits(); if (!query.hasLimit() && hits.totalHits() >= maxResultsSize) log.warn("Query result set truncated to first [{}] elements for query: {}", maxResultsSize, query); List<String> result = new ArrayList<String>(hits.hits().length); for (SearchHit hit : hits) { result.add(hit.id()); } return result; } ElasticSearchIndex(Configuration config); @Override void register(String store, String key, KeyInformation information, BaseTransaction tx); XContentBuilder getNewDocument(final List<IndexEntry> additions, KeyInformation.StoreRetriever informations, int ttl); @Override void mutate(Map<String, Map<String, IndexMutation>> mutations, KeyInformation.IndexRetriever informations, BaseTransaction tx); void restore(Map<String,Map<String, List<IndexEntry>>> documents, KeyInformation.IndexRetriever informations, BaseTransaction tx); FilterBuilder getFilter(Condition<?> condition, KeyInformation.StoreRetriever informations); @Override List<String> query(IndexQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx); @Override Iterable<RawQuery.Result<String>> query(RawQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx); @Override boolean supports(KeyInformation information, TitanPredicate titanPredicate); @Override boolean supports(KeyInformation information); @Override String mapKey2Field(String key, KeyInformation information); @Override IndexFeatures getFeatures(); @Override BaseTransactionConfigurable beginTransaction(BaseTransactionConfig config); @Override void close(); @Override void clearStorage(); static final ImmutableList<String> DATA_SUBDIRS; static final ConfigNamespace ELASTICSEARCH_NS; static final ConfigOption<Boolean> CLIENT_ONLY; static final ConfigOption<String> CLUSTER_NAME; static final ConfigOption<Boolean> LOCAL_MODE; static final ConfigOption<Boolean> CLIENT_SNIFF; static final ConfigOption<String> INTERFACE; static final ConfigOption<Boolean> IGNORE_CLUSTER_NAME; static final ConfigOption<String> TTL_INTERVAL; static final ConfigOption<String> HEALTH_REQUEST_TIMEOUT; static final ConfigOption<Boolean> LOAD_DEFAULT_NODE_SETTINGS; static final ConfigOption<Boolean> USE_EDEPRECATED_IGNORE_UNMAPPED_OPTION; static final ConfigNamespace ES_EXTRAS_NS; static final ConfigNamespace ES_CREATE_NS; static final ConfigOption<Long> CREATE_SLEEP; static final ConfigNamespace ES_CREATE_EXTRAS_NS; static final int HOST_PORT_DEFAULT; }
@Test public void testUnescapedDollarInSet() throws Exception { initialize("vertex"); Multimap<String, Object> initialDoc = HashMultimap.create(); initialDoc.put(PHONE_SET, "12345"); add("vertex", "unescaped", initialDoc, true); clopen(); Multimap<String, Object> updateDoc = HashMultimap.create(); updateDoc.put(PHONE_SET, "$123"); add("vertex", "unescaped", updateDoc, false); add("vertex", "other", getRandomDocument(), true); clopen(); assertEquals("unescaped", tx.query(new IndexQuery("vertex", PredicateCondition.of(PHONE_SET, Cmp.EQUAL, "$123"))).get(0)); assertEquals("unescaped", tx.query(new IndexQuery("vertex", PredicateCondition.of(PHONE_SET, Cmp.EQUAL, "12345"))).get(0)); }