简体   繁体   中英

How to do full text search matching on partial Elasticsearch queries

I use Elasticsearch with Laravel, I implement everything and it works with simple match queries like in the code above.

'body' => [
                "query" => [
                       "bool" => [
                           "should" => [
                            ["regexp" => [
                               "tags" => [
                                   "value" => ".{2,8}" . $query . ".*",
                            ]
                            ],
                                ],
                            ["wildcard" => [
                               "tags" => [
                                   "value" => "*" . $query . "*",
                                   "boost" => 1.0,
                                   "rewrite" => "constant_score"
                                    ]
                                ]
                            ]
                        ]],
                    ], "highlight" => [
                    "fields" => [
                        "tags" => ["type" => "plain"]
                    ]
                ]
          ]

I receive good results like on query "java" I receive both "javascript" & "nativjavascript" But the problem is with receiving results in phrases.

I want to type in query "java react" and want to receive this results: "java","javascript","javascript reactjs", "reactjs","react", "nativjavascript".

I am not familiar with Laravel, hence can't provide you the exact syntax but can tell the approach and how I solved this use-case in my application.

  1. Create an n-gram based analyzer on your searchable fields, which would split tokens based on the n-gram you configure.
  2. Split your search term based on the space , in your case java react , should be split into 2 search term java and react .
  3. Use keyword analyzer as a search_time analyzer on the search fields.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM