2012-05-09 19 views
0

我已经创建了我的指标和映射这个JSON在ElasticSearch我们应该在查询字符串default_field使用NGRAM分析

// 1st Mapping 
    http://localhost:9200/hdm/entities/_mapping 
    { 
      "entities" : { 
       "properties": { 
        "name": { "type": "string", "boost": 2.0, "analyzer": "snowball" }, 
        "description": { "type": "string", "analyzer": "nGram" } 
       } 
      } 
     } 
// 2nd Mapping 
    http://localhost:9200/hdm/products/_mapping 
    { 
     "products": { 
      "_parent": { "type": "entities" }, 
      "properties": { 
       "name": { "type": "string", "boost": 2.0, "analyzer": "snowball" }, 
       "code": { "type": "string", "analyzer": "snowball" }, 
       "segment": { "type": "string", "analyzer": "snowball" }, 
       "description": { "type": "string", "analyzer": "snowball" } 
      } 
     } 
    } 

现在我已经使用JSON

http://localhost:9200/hdm/entities/100 
    { 
     "name":"Entity 001", 
     "description":"this is the company or an organization which provides the whole medicine, tablets injunction for the problem of human being those noting worth gaining was ever gained without effort 

", 
     "itype":"entities" 
    } 

    http://localhost:9200/hdm/products/101?parent=100 
    { 
     "name":"biorich", 
     "description":"the tablet para is used to rectify the person from the all types of pain in the body, kingston , car, bat, ball, description of the products", 
     "code":"COD19202", 
     "segment":"SEG1022", 
     "itype":"products" 
    } 
进行索引,索引一些文档

搜索我用这个JSON

{ 
    "query": { 
    "filtered": { 
     "query": { 
     "bool": { 
      "should": [ 
      { 
       "has_child": { 
       "type": "products", 
       "query": { 
        "query_string": { 
        "query": "tab" 
        } 
       } 
       } 
      }, 
      { 
       "query_string": { 
       "query": "tablet" 
       } 
      } 
      ] 
     } 
     }, 
     "filter": { 
     "or": [ 
      { 
      "term": { 
       "itype": "entities" 
      } 
      } 
     ] 
     } 
    } 
    } 
} 

我没有得到的结果,但我改变了查询〜应变这样g然后我得到的结果

 "query_string": { 
     "default_field" : "description" 
     "query": "tablet" 
     } 

你能不能跟我确认,我们应该提到default_field查询字符串中获得NGRAM分析结果呢?我的分析仪配置如下

index.analysis.analyzer.mynGram.type: custom 
index.analysis.analyzer.mynGram.tokenizer: standard 
index.analysis.analyzer.mynGram.filter: [lowercase, mynGramFilter] 
index.analysis.filter.mynGramFilter.type: nGram 
index.analysis.filter.mynGramFilter.min_gram: 1 
index.analysis.filter.mynGramFilter.max_gram: 10 

回答

2

当在查询中没有指定"default_field"是,elasticsearch使用特殊_all字段进行搜索。由于您没有更改默认分析仪,也没有为映射中的_all字段指定分析仪,因此使用standard分析仪对_all字段执行搜索。

相关问题