2016-09-02 37 views
0

使用elasticsearch我尝试通过单词“滑雪”查找所有项目。Elasticsearch查找输入词和所有同义词

我的映射(PHP阵列):

"properties" => [ 
    "title" => [ 
     "type" => "string", 
     "boost" => 1.0, 
     "analyzer" => "autocomplete" 
    ] 
] 

设置:

"settings"=> [ 
    "analysis" => [ 
     "analyzer" => [ 
      "autocomplete" => [ 
       "type" => "custom", 
       "tokenizer" => "standard", 
       "filter" => ["lowercase", "trim", "synonym", "porter_stem"], 
       "char_filter" => ["html_strip"] 
      ] 
     ], 
     "filter" => [ 
      "synonym" => [ 
       "type" => "synonym", 
       "synonyms_path" => "analysis/synonyms.txt" 
      ] 
     ] 
    ] 
] 

搜索查询:

[ 
    "index" => "articles", 
    "body" => [ 
     "query" => [ 
      "filtered" => [ 
       "query" => [ 
        "bool" => [ 
         "must" => [ 
          "indices" => [ 
           "indices" => ["articles"], 
           "query" => [ 
            "bool" => [ 
             "should" => [ 
              "multi_match" => [ 
               "query" => "skiing", 
               "fields" => ["title"] 
              ] 
             ] 
            ] 
           ] 
          ] 
         ] 
        ] 
       ] 
      ] 
     ], 
     "sort" => [ 
      "_score" => [ 
       "order" => "desc" 
      ] 
     ] 
    ], 
    "size" => 10, 
    "from" => 0, 
    "search_type" => "dfs_query_then_fetch", 
    "explain" => true 
]; 

在sysnonyms.txt具有滑雪=>黄原。

我想要得到与“滑雪”的所有项目(因为它是输入字),“滑雪”(由porter_stem标记生成器),然后在“黄原”(由同义词文件)。但只有用词“xanthic”才能得到结果。

请告诉我为什么?我如何配置索引?

回答

0

Thanx,但这是decision。我改变映射:

"properties" => [ 
    "title" => [ 
     "type" => "string", 
     "boost" => 1.5, 
     "analyzer" => "standard", 
     "fields" => [ 
      "english" => [ 
       "type" => "string", 
       "analyzer" => "standard", 
       "search_analyzer" => "english", 
       "boost" => 1.0 
      ], 
      "synonym" => [ 
       "type" => "string", 
       "analyzer" => "standard", 
       "search_analyzer" => "synonym", 
       "boost" => 0.5 
      ] 
     ] 
    ] 
] 

设置:

"settings"=> [ 
    "analysis" => [ 
     "analyzer" => [ 
      "synonym" => [ 
       "type" => "custom", 
       "tokenizer" => "standard", 
       "filter" => ["lowercase", "trim", "synonym"], 
       "char_filter" => ["html_strip"] 
      ] 
     ], 
     "filter" => [ 
      "synonym" => [ 
       "type" => "synonym", 
       "synonyms_path" => "analysis/synonyms.txt" 
      ] 
     ] 
    ] 
] 
1

在同义词文件中,你需要有“滑雪,xanthic”。你现在用这种方式代替了用xanthic滑雪,但是你想保留两者。我认为你需要重新编制数据来查看变化。