Skip to content
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

KNQL Does not query exact phrases containing multiple tokens/words #43

Closed
aleeVS opened this issue Feb 21, 2018 · 7 comments
Closed

KNQL Does not query exact phrases containing multiple tokens/words #43

aleeVS opened this issue Feb 21, 2018 · 7 comments

Comments

@aleeVS
Copy link

aleeVS commented Feb 21, 2018

Plugin version:
6.2.1

Kibana version:
6.2.1

Plugins installed:
Elastic search 6.2.0

Description of the problem including expected versus actual behavior:
Unable to query body of the document for multi-phrase. If nesting is turned off, this works fine.
Example: finding "test post" from "this is a test post"

Expected behavior: find posts that contains the phrase
Actual behavior: "No results found"
The only way to fix this is to use keyword instead of text as the type, and then query body.keyword~="the post"

Steps to reproduce:

  1. add posts
    curl -XPUT 'localhost:9200/vs_views/_doc/1?refresh&pretty' -H 'Content-Type: application/json' -d'
    {
    "body": "This is a text of the post",
    "post_date": "2017-01-01",
    }

curl -XPUT 'localhost:9200/vs_views/_doc/2?refresh&pretty' -H 'Content-Type: application/json' -d'
{
"body": "This is a another text of the post",
"post_date": "2016-12-01",
}
2. in kibana "Management" --> index pattern --> create index pattern; and then turn on nested fields
3. in kibana "Discover" search 'body="the post"'

Errors in browser console (if relevant):
No results found
Unfortunately I could not find any results matching your search. I tried really hard. I looked all over the place and frankly, I just couldn't find anything good. Help me, help you. Here are some ideas:

Refine your query
The search bar at the top uses Elasticsearch's support for Lucene Query String syntax. Let's say we're searching web server logs that have been parsed into a few fields.

Examples:
Find requests that contain the number 200, in any field:
200
Or we can search in a specific field. Find 200 in the status field:
status:200
Find all status codes between 400-499:
status:[400 TO 499]
Find status codes 400-499 with the extension php:
status:[400 TO 499] AND extension:PHP
Or HTML
status:[400 TO 499] AND (extension:php OR extension:html)
Provide logs and/or server output (if relevant):

If using docker, include your docker file:

@aleeVS
Copy link
Author

aleeVS commented Feb 21, 2018

Normal query using lucene query syntax without nested support
image

@aleeVS
Copy link
Author

aleeVS commented Feb 21, 2018

Activating nested support on an index, same query now cannot find the multi-token phrase
image

@ppadovani
Copy link
Owner

Thanks for the report, this looks like a limitation in the KNQL language. The equals(=) operator is a term query, the LIKE(~=) is wildcard. I did not code in a match_phrase into the language, as it wasn't a requirement at the time I built this out.

It would seem to me that the match_phrase is similar in behavior to a wildcard query without the actual wildcard operators. I.e. Re-using the concept of a LIKE makes sense in the language.

With this in mind, I will update the parser to check the value of the string passed into the LIKE expression and use wildcard if a * or ? is present, otherwise it will use match_phrase.

ppadovani pushed a commit that referenced this issue Feb 21, 2018
@aleeVS
Copy link
Author

aleeVS commented Feb 21, 2018

Thank you Pierre!
Just to be clear, it needs to be able to match MULTIPLE tokens, not just a SINGLE token with wild cards.

Also, alternatively, could the Nested Support be used without KNQL?

@ppadovani
Copy link
Owner

ppadovani commented Feb 21, 2018

Yep. I've got the code working with your example.. it really was only about 10-12 lines of code to make the change.

Unfortunately, KNQL is required for indices with nested fields. The reason for this is the need to pre-parse the query and generate a native elastic search query that injects the correct nested path information into the query. In order to do this, the plugin gathers more information about the index from elastic search, and keeps track of the field information. When you build a query, the plugin's parser uses its knowledge of the index's mapping to properly generate nested queries without you having to manually inject additional information.

This breaks down under certain circumstances, as stated in the KNQL documentation. Hence the need for the EXISTS keyword to properly scope nested queries.

So, I'm sure your wondering why the lucene query language in Kibana doesn't work with nested fields. The main reason is that Kibana doesn't actually parse the query, it just blindly passes it to elastic search and has elastic search do the processing. Additionally, the lucene query language has no concept around nested fields built into it.

I've release 6.2.1-1.0.2 which should solve this issue. Please install the new version and let me know if it works for you. Then I'll back port to the other releases.

ppadovani added a commit that referenced this issue Feb 22, 2018
ppadovani added a commit that referenced this issue Feb 22, 2018
ppadovani added a commit that referenced this issue Feb 22, 2018
ppadovani added a commit that referenced this issue Feb 22, 2018
ppadovani added a commit that referenced this issue Feb 22, 2018
ppadovani added a commit that referenced this issue Feb 22, 2018
ppadovani added a commit that referenced this issue Feb 22, 2018
@ppadovani
Copy link
Owner

I believe this is now resolved and back ported to all releases. Please let me know if this is still an issue and I'll reopen.

@aleeVS
Copy link
Author

aleeVS commented Feb 23, 2018 via email

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

No branches or pull requests

2 participants