- /**
- * The value which the field must contain in order to have a match.
- */
- private Object value;
-
- /**
- * For multi field queries only. Determines the rules for whether or not a document matches
- * the query, as follows:
- *
- * <p>"and" - At least one occurrence of every supplied value must be present in any of the
- * supplied fields.
- *
- * <p>"or" - At least one occurrence of any of the supplied values must be present in any of
- * the supplied fields.
- */
- private String operator;
-
- @JsonProperty("analyzer")
- private String searchAnalyzer;
-
-
- public String getField() {
- return field;
- }
-
- public void setField(String field) {
- this.field = field;
- }
-
- public Object getValue() {
- return value;
- }
-
- public void setValue(Object value) {
- this.value = value;
- }
-
- private boolean isNumericValue() {
- return ((value instanceof Integer) || (value instanceof Double));
- }
-
- public String getOperator() {
- return operator;
- }
-
- public void setOperator(String operator) {
- this.operator = operator;
- }
-
- public String getSearchAnalyzer() {
- return searchAnalyzer;
- }
-
- public void setSearchAnalyzer(String searchAnalyzer) {
- this.searchAnalyzer = searchAnalyzer;
- }
-
- /**
- * This method returns a string which represents this query in syntax
- * that is understandable by ElasticSearch and is suitable for inclusion
- * in an ElasticSearch query string.
- *
- * @return - ElasticSearch syntax string.
- */
- public String toElasticSearch() {
-
- StringBuilder sb = new StringBuilder();
-
- sb.append("{");
-
- // Are we generating a multi field query?
- if (isMultiFieldQuery()) {
-
- // For multi field queries, we have to be careful about how we handle
- // nested fields, so check to see if any of the specified fields are
- // nested.
- if (field.contains(".")) {
-
- // Build the equivalent of a multi match query across one or more nested fields.
- toElasticSearchNestedMultiMatchQuery(sb);
-
- } else {
-
- // Build a real multi match query, since we don't need to worry about nested fields.
- toElasticSearchMultiFieldQuery(sb);
- }
- } else {
-
- // Single field query.
-
- // Add the necessary wrapping if this is a query against a nested field.
- if (fieldIsNested(field)) {
- sb.append("{\"nested\": { \"path\": \"").append(pathForNestedField(field))
- .append("\", \"query\": ");
- }
-
- // Build the query.
- toElasticSearchSingleFieldQuery(sb);
-
- if (fieldIsNested(field)) {
- sb.append("}}");
- }