Skip to content

Nested Criteria queries must consider sub-fields #1758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sothawo opened this issue Apr 4, 2021 · 0 comments · Fixed by #1760
Closed

Nested Criteria queries must consider sub-fields #1758

sothawo opened this issue Apr 4, 2021 · 0 comments · Fixed by #1760
Assignees
Labels
type: bug A general bug

Comments

@sothawo
Copy link
Collaborator

sothawo commented Apr 4, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant