Elasticsearch IK Configuring dynamic synonyms

Source: Internet
Author: User
Tags http request lowercase
Use Environment elasticsearch5.1.1 kibana5.1.1 Synonyms plugin 5.1.1 Installing plugins download the corresponding elasticsearch-analysis-dynamic-synonym-5.1.1.zip, unzip to the local elasticsearch/plugins directory, restart ES first way local file Description: for local files: mainly through the file modification timestamp (Modify time) to determine whether to reload in the Elasticsearch/config directory, set up the analysis directory, and put Synonym.txt in the profile, add the following line of synonyms to the first line of the file to testtomato, tomato, virgin

ES set index and custom parser

Put/megacorp
{"mappings": {"employee": {"Properties": {"
        name": {
          "type": "Text",
          " Analyzer ":" Ik-index ",  //parser used to specify index
          " Search_analyzer ":" Ik-smart "//parser to specify search time}
      }
  }
  ,
  "settings": {"Analysis": {"filter": {"local_synonym": {"
            type": "Dynamic _synonym ",
            " Synonyms_path ":" Analysis/synonym.txt "  
        }
      ,
      " Analyzer ": {
        " Ik-index ": {
          "Type": "Custom",
          "Tokenizer": "Ik_max_word",
          "filter": [
              "local_synonym"   //filter synonyms
           ]
        },
        "Ik-smart": {
          "type": "Custom",
          "Tokenizer": "Ik_smart",
          "filter": [
              "Local_ Synonym "]}}}}
once set up, you can use the following command to see if the synonym is configured successfully
Get/megacorp/_analyze
{
  "Analyzer": "Ik-index",
  "text": "Tomato"
}
The correct segmentation results are as follows:
{"
  tokens": [
    {
      "token": "Tomato",
      "Start_offset": 0,
      "End_offset": 3,
      "type": "Cn_word",
      "Position": 0
    },
    {
      "token": "Tomato",
      "Start_offset": 0,
      "End_offset": 3,
      "type": "Synonym" ,
      "position": 0
    },
    {
      "token": "Saint",
      "Start_offset": 0,
      "End_offset": 3,
      "type": "Synonym",
      "position": 0
    }
  ]
}
Insert 2 data:
PUT/MEGACORP/EMPLOYEE/1
{
    "name": "Cherry Fruit"
}

put/megacorp/employee/2
{
    "name": "Tomato"
}
search for tomatoes and you will find the records of tomatoes and cherry berries:
Get/megacorp/employee/_search
{"
    query": {"
      match": {
        "name": "Tomato"
}}}
The second way of remote interface Description: This HTTP request needs to return two headers, one is last-modified, the other is an ETag, and as long as there is a change, the plugin will fetch new synonyms to update the corresponding synonyms. write an interface locally
the interface returned requires the following three properties to be set
$response->setlastmodified ($lastModified);
$response->setetag ($etag, true);
$response->headers->set (' Content-type ', ' text/plain ');
Note: Nginx After opening gzip, if there is an ETAG will call Ngx_http_clear_etag to clear it, the solution is simple: as long as PHP returns the ETag is weak etag, then everything will be normal. And the so-called weak etag, which is the weak etag, is relative to the normal etag, the manifestation is the etag in front plus w/
w/"Db8b38e8a3257a2f195b727eceb2c5d3"
here is the configuration for setting up remote, local synonyms

Put/megacorp
{"Settings": {"index": {"Number_of_shards": "5", "Number_of_replicas": "1", "Analysis": { "Filter": {"remote_synonym": {"type": "Dynamic_synonym", "Synonyms_path": "Http://1 92.168.78.37:10001/synonym.txt "," Interval ": ten}," Edgengramfilter ": {" type "
          : "Edge_ngram", "Min_gram": 1, "Max_gram": [+]}, "Analyzer": {
              "Ngramindex": {"type": "Custom", "Tokenizer": "Keyword", "filter": [ "Edgengramfilter", "lowercase"]}, "Ngramlowercase": {"filter
          ": [" lowercase "]," type ":" Custom "," Tokenizer ":" Ngramtokenizer " }, "Ikindex": {"filter": ["remote_synonym"], "type": "Custom", "tOkenizer ":" Ik_max_word "}," Iksearch ": {" type ":" Custom "," Tokenizer ":" ik_s Mart "}," Keywordlowercase ": {" type ":" Custom "," Filter ": [" Lo Wercase "]," tokenizer ":" Keyword "}}," Tokenizer ": {" Ngramt
      Okenizer ": {" type ":" NGram "," Min_gram ":" 1 "," Max_gram ":" 3 "}}
          }}}, "mappings": {"type1": {"Properties": {"title": {"type": "Text",
              "Fields": {"ik": {"Analyzer": "Ikindex", "Search_analyzer": "Iksearch",
              "Type": "Text"}, "Keywordlowercase": {"Analyzer": "Keywordlowercase",
              "Type": "Text"}, "Ngram": {"Analyzer": "Ngramlowercase",
        ' Type ': ' Text '    }
          }
        }
      }
    }
  }
} 

{"Mappings": {"employee": {"Properties": {"name": {"type": "Text", "Analyzer": "Ik-index",//parser to specify index Search_analy Zer ":" Ik-smart "//Specify Parser}}}," Settings ": {" Analysis ": {" filter ": {" remote_synonym ": {" type ":" Dynamic_syn Onym "," Synonyms_path ":" Http://localhost/synonym/list "," Interval ": 60//No 60s tuning Interface}," local_synonym ": {" type ":" Dy Namic_synonym "," Synonyms_path ":" Analysis/synonym.txt "}," Analyzer ": {" Ik-index ": {" type ":" Custom "," Tokenizer ":" Ik_max_word "," Filter ": [" remote_synonym ",//filtering the remote synonym" local_synonym "//filtering the local synonym]}," Ik-smart ": {" type ":" Custom "," Tokenizer ":" Ik_smart "," Filter ": [" local_synonym "]}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.