0

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".

halfer
  • 19,824
  • 17
  • 99
  • 186
Imediasun
  • 81
  • 1
  • 1
  • 8
  • Possible duplicate of [Elasticsearch: Find substring match](https://stackoverflow.com/questions/23243867/elasticsearch-find-substring-match) – halfer Jun 04 '19 at 17:17

1 Answers1

1

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.
halfer
  • 19,824
  • 17
  • 99
  • 186
Amit
  • 30,756
  • 6
  • 57
  • 88
  • Amit, could you send please your query of elasticsearch – Imediasun Jun 04 '19 at 14:25
  • 1
    @lmediasun: I would generally discourage Amit from "sending you the query". It probably isn't as simple as that - this answer is very good in the sense that it has done some research for you. The best next step for you is to research some of the ideas to move yourself forward using a fresh solo effort. – halfer Jun 04 '19 at 17:00
  • 1
    If you can look into which direction you prefer, based on your specific use-case, you could add a small follow-up question in this thread, if it is trivial. However, your chosen direction may produce a new question that is sufficiently different from this one, at which point you could accept Amit's answer, and ask a new and separate question. I encourage you to ask for help, but only when you have genuinely exhausted your own research capabilities at each new juncture - that is how we all improve as engineers. – halfer Jun 04 '19 at 17:04
  • @lmediasun: I don't understand your question (and you'll need to ping me using `@halfer` if you want me to see your messages). – halfer Jun 04 '19 at 22:37
  • @halfer thanks a lot for your kind words and helping new users understand SO philosophy better :-) . – Amit Jun 05 '19 at 02:42
  • @AmitKhandelwal I will accept your answer of course if it will help me, but now I can not understand How n-gram will help me if I dont know what phrase will enter client, please show me in code of elastic settings How I can use it on exapmle of my quert "java react" – Imediasun Jun 06 '19 at 10:15