Query match in elasticsearch


(Hilal) #1

Hi,
I want to do text query but my query result is not true.

For example:
Text1: Road will be made in Turkey
Text2: Mosque will be made
Text3: They are comming

Query: http://10.0.2.15:8080/filter.php?text_field=Road will be made

result :

Road will be made
Mosque will be made

My wish is to show only the first text(text1).

My codes:

PUT /index
{
  "settings": {
    "analysis": {
      "filter": {
          "turkish_lowercase": {
          "type":       "lowercase",
          "language":   "turkish"
        }
      },
      "analyzer": {
        "turkish": {
          "tokenizer":  "standard",
          "filter": [
            "turkish_lowercase"
          ]
        }
      }
    }
  }          
}

 PUT index/type/_mapping
        {
          "properties": {
            "text": {
              "type": "string",
              "index": "analyzed",
              "analyzer": "turkish""
              
            }
          }
        }

How can I do? Can I use fuzzy method?
if so how do I do ?

Thank you


(Vatsal Patel) #2

You can do this by removing tokenizer from your analyzer.This will gives you exact query string matching.I hope it will work for you.


(David Pilato) #3

Which query are you using behind the scene?
Match? QueryString?


(Hilal) #4

Hi,
I tried removing tokenizer from your analyzer but it is still the same Vatsal_Patel.

PUT /ihaleler
{
  "settings": {
    "analysis": {
      "filter": {
          "turkish_lowercase": {
          "type":       "lowercase",
          "language":   "turkish"
        }}}}}

I am using match query. I've written the wrong title. I am sorry Dadonet.

PHP codes:

unset($filter_text_field);
    if(isset($_GET['text_field'])){
        $filter_text_field['match']['text_field']=$_GET['text_field'];
    }

if(is_array($filter_text_field)){
    $searchParams['body']['query']['bool']['must']=$filter_text_field;
}

(Hilal) #5

I found it. I used "match_phrase" instead of "match"

$filter_text_field['match_phrase']['text_field']=$_GET['text_field'];

Thanks anyway.

Have a good day.


(system) #6