Skip to content

Nested Criteria queries must consider sub-fields #1758

Closed
@sothawo

Description

@sothawo

With #1753 CriteriaQuery now supports nested queries. There is an issue with these nested queries, when the path expression ends with an inner field.

When in the index (cities) we have the following mapping:

{
    "cities": {
        "mappings": {
            "properties": {
                "name": {
                    "type": "text"
                },
                "houses": {
                    "type": "nested",
                    "properties": {
                        "street": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword"
                                }
                            }
                        },
                        "street-number": {
                            "type": "text"
                        }
                    }
                }
            }
        }
    }
}

and we want so search for street names by the keyword sub-field with this query:

new CriteriaQuery(new Criteria("houses.street.keyword").is("Main Street"))

then the following query must be built:

{
  "query": {
    "nested": {
      "path": "houses",
      "query": {
        "bool": {
          "must": [
            {
              "query_string": {
                "query": "Main Street",
                "fields": [
                  "houses.street.keyword"
                ]
              }
            }
          ]
        }
      }
    }
  }
}

But currently the wrong path (houses.street instead of houses) is sent as the path prefix is created by stripping the last segment (here keyword).

This must be fixed, so that sub-fields are considered when building the path expression.With #1753 CriteriaQuery now supports nested queries. There is an issue with these nested queries, when the path expression ends with an inner field.

When in the index (cities) we have the following mapping:

{
    "cities": {
        "mappings": {
            "properties": {
                "name": {
                    "type": "text"
                },
                "houses": {
                    "type": "nested",
                    "properties": {
                        "street": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword"
                                }
                            }
                        },
                        "street-number": {
                            "type": "text"
                        }
                    }
                }
            }
        }
    }
}

and we want so search for street names by the keyword sub-field with this query:

new CriteriaQuery(new Criteria("houses.street.keyword").is("Main Street"))

then the following query must be built:

{
  "query": {
    "nested": {
      "path": "houses",
      "query": {
        "bool": {
          "must": [
            {
              "query_string": {
                "query": "Main Street",
                "fields": [
                  "houses.street.keyword"
                ]
              }
            }
          ]
        }
      }
    }
  }
}

But currently the wrong path (houses.street instead of houses) is sent as the path prefix is created by stripping the last segment (here keyword).

This must be fixed, so that sub-fields are considered when building the path expression.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions