0

can anyone help me match results by words in elasticsearch regex? I am new to regex.

If I have strings as per below :

  • string 1: "Hello, are you fine?"
  • string 2: "Does she use youtube?"

If I search for "you" word in elastic search then I want just "string 1" as an output. and If I search for "are you" then it should also give me a "string 1" as an output.

I tried with below regex but not giving me the expected output :

  • pattern 1: ".*you.*" - it's giving me both string as an output.
  • pattern 2: "/\syou\s/" - it's not giving me an nay output.

Can anyone help me to fix this ?

EricLavault
  • 12,130
  • 3
  • 23
  • 45
  • 1
    Did you try with `/\byou\b/` ? – EricLavault Jan 08 '20 at 13:37
  • @EricLavault I tried with /\byou\b/ but it's not working. :( – Yellow Digital Labs Jan 08 '20 at 13:52
  • Please post your full search query. Are the quotation marks actually part of your strings and/or search patterns? – BadHorsie Jan 08 '20 at 13:55
  • curl -H 'Content-Type: application/json' -XPOST 'https://elastic:d0vEW5M90ItbwHuX9ttNo0ig@9fe010fe485944eca402f7104ff565bc.us-west-1.aws.found.io:9243/products_master/_search?pretty&scroll=10m&size=10' -d '{ "query": { "bool": { "must": [{ "bool": { "should": [ {"regexp": {"name": "/\bbeds\b/"}}, {"regexp": {"brand_data.brand_name": "/\bbeds\b/"}}, {"regexp": {"model_number": "/\bbeds\b/"}}, {"regexp": {"Categories": "/\bbeds\b/"}} ] } } ] } }, "aggs": { "products-by-brand": { "terms": { "field": "brand_id", "size": 500 } } } } ' – Yellow Digital Labs Jan 08 '20 at 14:04
  • 1
    Lucene has no `\b` support – Wiktor Stribiżew Jan 08 '20 at 14:32
  • so, what can I use for word search? can anyone tell me – Yellow Digital Labs Jan 09 '20 at 10:07

0 Answers0