Skip to content

[Management] Allow wildcard anywhere in the search query - #16109

Merged
chrisronline merged 4 commits into
elastic:masterfrom
chrisronline:fix/16098
Jan 19, 2018
Merged

chrisronline merged 4 commits into
elastic:masterfrom
chrisronline:fix/16098

Conversation

@chrisronline

@chrisronline chrisronline commented Jan 17, 2018 •

Copy link
Copy Markdown
Contributor

Fixes #16098

This PR addresses two things:

  1. Ensures that queries like *o* properly match an index like foo. Before this PR, only ending wildcards did anything.

  2. Addresses a bug where the number of results showing on the index pattern creation page was fewer than expected. This is because the proper limit was never passed into the ES query and it used the default limit (which I think is 10)

Testing

Ensure that using a wildcard in the search query, in places other than the end, match indices properly.

Tests

Tests have been updated to handle this scenario.

@cjcenizal cjcenizal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I tested this in browser and it works. I have a couple small comments. Have you tested that MAX_SEARCH_SIZE has the expected result when you have a massive number of indices?

});
});

it('should support queries with wildcards in various places again', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this test verifying which the one before it does not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be verifying that a wildcard not at the end of the query still works

if (query.endsWith('*') && name.indexOf(query.substring(0, query.length - 1)) === 0) {
return true;

const regexQuery = query.startsWith('*')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about extracting this logic into a helper function, and adding a couple light tests for it? I think it would improve readability of this code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like the right move!

allIndices: [{ name: 'kibana' }, { name: 'kibana2' }, { name: 'es' }],
exactMatchedIndices: [{ name: 'kibana' }, { name: 'kibana2' }],
partialMatchedIndices: [{ name: 'kibana' }, { name: 'kibana2' }],
visibleIndices: [{ name: 'kibana' }, { name: 'kibana2' }]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to think about in a later iteration, but I think we might be able to make these tests clearer if we pared the tests down to make assertions against just allIndices, exactMatchedIndices, partialMatchedIndices, and visibleIndices. This would result in more focused tests and I think it'd be easier to spot the relationships between the input and each specific type of output. It would result in more tests, however. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree. Great suggestion!

@chrisronline

Copy link
Copy Markdown
Contributor Author

@cjcenizal I haven't tested it like that. Rather, I've just decreased the number to something small, like 3 and it works as expected. Do you think it's necessary to test it like you're describing?

@cjcenizal

Copy link
Copy Markdown
Contributor

I was just thinking of this part of the PR description:

Addresses a bug where the number of results showing on the index pattern creation page was fewer than expected. This is because the proper limit was never passed into the ES query and it used the default limit (which I think is 10)

Is there a way we can verify this behaves as expected now?

@cjcenizal cjcenizal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏇 Sweet! Just had a couple minor comments about test readability.

import { isQueryAMatch } from '../is_query_a_match';

describe('isQueryAMatch', () => {
it('should handle straight up matches', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Handles" is a bit ambiguous to me. Can we rephrase/restructure these statements to assert the nature of the outcome? I'd suggest:

describe('returns true', () => {
  it('for an exact value')
  it('for a pattern with a trailing wildcard')
  it('for a pattern with a leading wildcard')
  it('for a pattern with a middle and trailing wildcard')
  it('for a pattern with a middle wildcard')
  it(`for a pattern that's only a wildcard`)
});

describe('returns false', () => {
  it('for a non-matching pattern')
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!


// This shouldn't be necessary but just used as a safety net
// so the page doesn't bust if the user types in some weird
// query that throws an exception when converting to a RegExp

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice comment!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

];

const result = getMatchedIndices(indices, matchedIndices, query, true);
describe('visibleIndices', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re our convo, I think these test would be easier to follow if we reverse the order of the "filtered" and "not filtered" assertions, so that the reader understands the baseline behavior first, and then can compare that with the "filtered" test to see how changing the last argument to false affects the output.

I also think being more verbose with the description would help make these tests clearer, e.g. by changing "should return unfiltered" to "returns all indices" and "should return filtered" to "excludes system indices".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

@chrisronline

Copy link
Copy Markdown
Contributor Author

Is there a way we can verify this behaves as expected now?

I just made a code change to handle and test this: ab6535d

Thoughts?

@cjcenizal cjcenizal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤜 💥 🤛 Awesome!

@chrisronline
chrisronline merged commit 8864755 into elastic:master Jan 19, 2018
chrisronline added a commit to chrisronline/kibana that referenced this pull request Jan 19, 2018
* Allow wildcard anywhere in the search query

* PR feedback for tests

* Update tests

* Throw exception when missing required parameter
@chrisronline
chrisronline deleted the fix/16098 branch January 19, 2018 14:14
chrisronline added a commit that referenced this pull request Jan 19, 2018
…6154)

* Allow wildcard anywhere in the search query

* PR feedback for tests

* Update tests

* Throw exception when missing required parameter
@chrisronline

Copy link
Copy Markdown
Contributor Author

Backport:

6.x: #16154

patrykkopycinski pushed a commit to patrykkopycinski/kibana that referenced this pull request May 6, 2026
* Allow wildcard anywhere in the search query

* PR feedback for tests

* Update tests

* Throw exception when missing required parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants