Skip to content

Change notes ES searches to use new denormalized fields

What does this MR do?

Related to #300843 (closed) and #300844 (closed)

  • Removes project joins from the Elasticsearch query used for notes (comments) scoped searches. It was not possible to separate group/project from global searches so this MR encompasses all of them.

  • Organizes the global/group/project service visibility specs so that notes have their own section and all 4 types of searchable notes are tested there.

  • Add shared specs for testing that the joins have been removed from the query if the add_permissions_data_to_notes_documents migration has completed

How to test

Setup for testing:

  • Enable Elasticsearch in GDK
  • Enable Advanced Search in Admin Settings

Perform a global, group, and project notes (comments) scoped search and verify using the Performance Bar that the Elasticsearch queries do not contain the has_parent joins

Screenshots (strongly suggested)

Elasticsearch queries before/after. All queries done with admin user and performance bar. Removing the joins for to the project documents means

  • replacing "has_parent" sections of the query with queries for visibility_level and appropriate project feature level which are now top level fields in the document
  • replacing all references to id when looking at project id with project_id which is a top level field in the document

Global

Before
{
  "query": {
    "bool": {
      "must": [
        {
          "simple_query_string": {
            "_name": "note:match:search_terms",
            "fields": [
              "note"
            ],
            "query": "*",
            "lenient": true,
            "default_operator": "and"
          }
        }
      ],
      "filter": [
        {
          "term": {
            "type": {
              "_name": "doc:is_a:note",
              "value": "note"
            }
          }
        },
        {
          "bool": {
            "_name": "note:authorized",
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:issues",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:issues:any",
                                        "value": 0
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:issues:enabled_or_private",
                                      "issues_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Issue",
                          "value": "Issue"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:merge_requests",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:merge_requests:any",
                                        "value": 0
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:merge_requests:enabled_or_private",
                                      "merge_requests_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:MergeRequest",
                          "value": "MergeRequest"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:snippets",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:snippets:any",
                                        "value": 0
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:snippets:enabled_or_private",
                                      "snippets_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Snippet",
                          "value": "Snippet"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:repository",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:repository:any",
                                        "value": 0
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:repository:enabled_or_private",
                                      "repository_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Commit",
                          "value": "Commit"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:visibility:10:issues",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:visibility:10",
                                        "value": 10
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:visibility:10:issues:enabled_or_private",
                                      "issues_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Issue",
                          "value": "Issue"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:visibility:10:merge_requests",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:visibility:10",
                                        "value": 10
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:visibility:10:merge_requests:enabled_or_private",
                                      "merge_requests_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:MergeRequest",
                          "value": "MergeRequest"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:visibility:10:snippets",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:visibility:10",
                                        "value": 10
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:visibility:10:snippets:enabled_or_private",
                                      "snippets_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Snippet",
                          "value": "Snippet"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:visibility:10:repository",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:visibility:10",
                                        "value": 10
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:visibility:10:repository:enabled_or_private",
                                      "repository_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Commit",
                          "value": "Commit"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:visibility:20:issues",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:visibility:20",
                                        "value": 20
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:visibility:20:issues:enabled_or_private",
                                      "issues_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Issue",
                          "value": "Issue"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:visibility:20:merge_requests",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:visibility:20",
                                        "value": 20
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:visibility:20:merge_requests:enabled_or_private",
                                      "merge_requests_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:MergeRequest",
                          "value": "MergeRequest"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:visibility:20:snippets",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:visibility:20",
                                        "value": 20
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:visibility:20:snippets:enabled_or_private",
                                      "snippets_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Snippet",
                          "value": "Snippet"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:visibility:20:repository",
                                "filter": [
                                  {
                                    "term": {
                                      "visibility_level": {
                                        "_name": "note:authorized:project:visibility:20",
                                        "value": 20
                                      }
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:visibility:20:repository:enabled_or_private",
                                      "repository_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Commit",
                          "value": "Commit"
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "note": {}
    },
    "number_of_fragments": 0,
    "pre_tags": [
      "gitlabelasticsearch→"
    ],
    "post_tags": [
      "←gitlabelasticsearch"
    ]
  }
}
After
{
  "query": {
    "bool": {
      "must": [
        {
          "simple_query_string": {
            "_name": "note:match:search_terms",
            "fields": [
              "note"
            ],
            "query": "findable text",
            "lenient": true,
            "default_operator": "and"
          }
        }
      ],
      "filter": [
        {
          "term": {
            "type": {
              "_name": "doc:is_a:note",
              "value": "note"
            }
          }
        },
        {
          "bool": {
            "_name": "note:authorized",
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Issue",
                          "value": "Issue"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:issues",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:issues:any",
                                "value": 0
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:issues:enabled_or_private",
                              "issues_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:MergeRequest",
                          "value": "MergeRequest"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:merge_requests",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:merge_requests:any",
                                "value": 0
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:merge_requests:enabled_or_private",
                              "merge_requests_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Snippet",
                          "value": "Snippet"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:snippets",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:snippets:any",
                                "value": 0
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:snippets:enabled_or_private",
                              "snippets_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Commit",
                          "value": "Commit"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:repository",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:repository:any",
                                "value": 0
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:repository:enabled_or_private",
                              "repository_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Issue",
                          "value": "Issue"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:visibility:10:issues",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:visibility:10",
                                "value": 10
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:visibility:10:issues:enabled_or_private",
                              "issues_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:MergeRequest",
                          "value": "MergeRequest"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:visibility:10:merge_requests",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:visibility:10",
                                "value": 10
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:visibility:10:merge_requests:enabled_or_private",
                              "merge_requests_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Snippet",
                          "value": "Snippet"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:visibility:10:snippets",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:visibility:10",
                                "value": 10
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:visibility:10:snippets:enabled_or_private",
                              "snippets_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Commit",
                          "value": "Commit"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:visibility:10:repository",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:visibility:10",
                                "value": 10
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:visibility:10:repository:enabled_or_private",
                              "repository_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Issue",
                          "value": "Issue"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:visibility:20:issues",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:visibility:20",
                                "value": 20
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:visibility:20:issues:enabled_or_private",
                              "issues_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:MergeRequest",
                          "value": "MergeRequest"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:visibility:20:merge_requests",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:visibility:20",
                                "value": 20
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:visibility:20:merge_requests:enabled_or_private",
                              "merge_requests_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Snippet",
                          "value": "Snippet"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:visibility:20:snippets",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:visibility:20",
                                "value": 20
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:visibility:20:snippets:enabled_or_private",
                              "snippets_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Commit",
                          "value": "Commit"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:visibility:20:repository",
                        "filter": [
                          {
                            "term": {
                              "visibility_level": {
                                "_name": "note:authorized:project:visibility:20",
                                "value": 20
                              }
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:visibility:20:repository:enabled_or_private",
                              "repository_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "note": {}
    },
    "number_of_fragments": 0,
    "pre_tags": [
      "gitlabelasticsearch→"
    ],
    "post_tags": [
      "←gitlabelasticsearch"
    ]
  }
}

Group

Before
{
  "query": {
    "bool": {
      "must": [
        {
          "simple_query_string": {
            "_name": "note:match:search_terms",
            "fields": [
              "note"
            ],
            "query": "*",
            "lenient": true,
            "default_operator": "and"
          }
        }
      ],
      "filter": [
        {
          "term": {
            "type": {
              "_name": "doc:is_a:note",
              "value": "note"
            }
          }
        },
        {
          "bool": {
            "_name": "note:authorized",
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:issues",
                                "filter": [
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:issues:membership:id",
                                      "id": [
                                        4
                                      ]
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:issues:enabled_or_private",
                                      "issues_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Issue",
                          "value": "Issue"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:merge_requests",
                                "filter": [
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:merge_requests:membership:id",
                                      "id": [
                                        4
                                      ]
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:merge_requests:enabled_or_private",
                                      "merge_requests_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:MergeRequest",
                          "value": "MergeRequest"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:snippets",
                                "filter": [
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:snippets:membership:id",
                                      "id": [
                                        4
                                      ]
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:snippets:enabled_or_private",
                                      "snippets_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Snippet",
                          "value": "Snippet"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:repository",
                                "filter": [
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:repository:membership:id",
                                      "id": [
                                        4
                                      ]
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:repository:enabled_or_private",
                                      "repository_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Commit",
                          "value": "Commit"
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "note": {}
    },
    "number_of_fragments": 0,
    "pre_tags": [
      "gitlabelasticsearch→"
    ],
    "post_tags": [
      "←gitlabelasticsearch"
    ]
  }
}
After
{
  "query": {
    "bool": {
      "must": [
        {
          "simple_query_string": {
            "_name": "note:match:search_terms",
            "fields": [
              "note"
            ],
            "query": "findable text",
            "lenient": true,
            "default_operator": "and"
          }
        }
      ],
      "filter": [
        {
          "term": {
            "type": {
              "_name": "doc:is_a:note",
              "value": "note"
            }
          }
        },
        {
          "bool": {
            "_name": "note:authorized",
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Issue",
                          "value": "Issue"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:issues",
                        "filter": [
                          {
                            "terms": {
                              "_name": "note:authorized:project:issues:membership:id",
                              "project_id": [
                                27,
                                28,
                                30,
                                32,
                                33,
                                34
                              ]
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:issues:enabled_or_private",
                              "issues_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:MergeRequest",
                          "value": "MergeRequest"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:merge_requests",
                        "filter": [
                          {
                            "terms": {
                              "_name": "note:authorized:project:merge_requests:membership:id",
                              "project_id": [
                                27,
                                28,
                                30,
                                32,
                                33,
                                34
                              ]
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:merge_requests:enabled_or_private",
                              "merge_requests_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Snippet",
                          "value": "Snippet"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:snippets",
                        "filter": [
                          {
                            "terms": {
                              "_name": "note:authorized:project:snippets:membership:id",
                              "project_id": [
                                27,
                                28,
                                30,
                                32,
                                33,
                                34
                              ]
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:snippets:enabled_or_private",
                              "snippets_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Commit",
                          "value": "Commit"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:repository",
                        "filter": [
                          {
                            "terms": {
                              "_name": "note:authorized:project:repository:membership:id",
                              "project_id": [
                                27,
                                28,
                                30,
                                32,
                                33,
                                34
                              ]
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:repository:enabled_or_private",
                              "repository_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "note": {}
    },
    "number_of_fragments": 0,
    "pre_tags": [
      "gitlabelasticsearch→"
    ],
    "post_tags": [
      "←gitlabelasticsearch"
    ]
  }
}

Project

Before
{
  "query": {
    "bool": {
      "must": [
        {
          "simple_query_string": {
            "_name": "note:match:search_terms",
            "fields": [
              "note"
            ],
            "query": "*",
            "lenient": true,
            "default_operator": "and"
          }
        }
      ],
      "filter": [
        {
          "term": {
            "type": {
              "_name": "doc:is_a:note",
              "value": "note"
            }
          }
        },
        {
          "bool": {
            "_name": "note:authorized",
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:issues",
                                "filter": [
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:issues:membership:id",
                                      "id": [
                                        4
                                      ]
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:issues:enabled_or_private",
                                      "issues_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Issue",
                          "value": "Issue"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:merge_requests",
                                "filter": [
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:merge_requests:membership:id",
                                      "id": [
                                        4
                                      ]
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:merge_requests:enabled_or_private",
                                      "merge_requests_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:MergeRequest",
                          "value": "MergeRequest"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:snippets",
                                "filter": [
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:snippets:membership:id",
                                      "id": [
                                        4
                                      ]
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:snippets:enabled_or_private",
                                      "snippets_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Snippet",
                          "value": "Snippet"
                        }
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "has_parent": {
                        "parent_type": "project",
                        "query": {
                          "bool": {
                            "should": {
                              "bool": {
                                "_name": "note:authorized:project:repository",
                                "filter": [
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:repository:membership:id",
                                      "id": [
                                        4
                                      ]
                                    }
                                  },
                                  {
                                    "terms": {
                                      "_name": "note:authorized:project:repository:enabled_or_private",
                                      "repository_access_level": [
                                        20,
                                        10
                                      ]
                                    }
                                  }
                                ]
                              }
                            }
                          }
                        }
                      }
                    },
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Commit",
                          "value": "Commit"
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "note": {}
    },
    "number_of_fragments": 0,
    "pre_tags": [
      "gitlabelasticsearch→"
    ],
    "post_tags": [
      "←gitlabelasticsearch"
    ]
  }
}
After
{
  "query": {
    "bool": {
      "must": [
        {
          "simple_query_string": {
            "_name": "note:match:search_terms",
            "fields": [
              "note"
            ],
            "query": "findable text",
            "lenient": true,
            "default_operator": "and"
          }
        }
      ],
      "filter": [
        {
          "term": {
            "type": {
              "_name": "doc:is_a:note",
              "value": "note"
            }
          }
        },
        {
          "bool": {
            "_name": "note:authorized",
            "should": [
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Issue",
                          "value": "Issue"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:issues",
                        "filter": [
                          {
                            "terms": {
                              "_name": "note:authorized:project:issues:membership:id",
                              "project_id": [
                                33
                              ]
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:issues:enabled_or_private",
                              "issues_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:MergeRequest",
                          "value": "MergeRequest"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:merge_requests",
                        "filter": [
                          {
                            "terms": {
                              "_name": "note:authorized:project:merge_requests:membership:id",
                              "project_id": [
                                33
                              ]
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:merge_requests:enabled_or_private",
                              "merge_requests_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Snippet",
                          "value": "Snippet"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:snippets",
                        "filter": [
                          {
                            "terms": {
                              "_name": "note:authorized:project:snippets:membership:id",
                              "project_id": [
                                33
                              ]
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:snippets:enabled_or_private",
                              "snippets_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              {
                "bool": {
                  "must": [
                    {
                      "term": {
                        "noteable_type": {
                          "_name": "note:authorized:noteable:is_a:Commit",
                          "value": "Commit"
                        }
                      }
                    },
                    {
                      "bool": {
                        "_name": "note:authorized:project:repository",
                        "filter": [
                          {
                            "terms": {
                              "_name": "note:authorized:project:repository:membership:id",
                              "project_id": [
                                33
                              ]
                            }
                          },
                          {
                            "terms": {
                              "_name": "note:authorized:project:repository:enabled_or_private",
                              "repository_access_level": [
                                20,
                                10
                              ]
                            }
                          }
                        ]
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "note": {}
    },
    "number_of_fragments": 0,
    "pre_tags": [
      "gitlabelasticsearch→"
    ],
    "post_tags": [
      "←gitlabelasticsearch"
    ]
  }
}

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Terri Chu

Merge request reports

Loading