elasticsearch 在ElasticSearch中,我们应该在nGram分析器的查询字符串中使用默认的_字段吗,elasticsearch,elasticsearch" /> elasticsearch 在ElasticSearch中,我们应该在nGram分析器的查询字符串中使用默认的_字段吗,elasticsearch,elasticsearch" />

elasticsearch 在ElasticSearch中,我们应该在nGram分析器的查询字符串中使用默认的_字段吗

elasticsearch 在ElasticSearch中,我们应该在nGram分析器的查询字符串中使用默认的_字段吗,elasticsearch,elasticsearch,我已经用这个JSON创建了我的索引和映射 // 1st Mapping http://localhost:9200/hdm/entities/_mapping { "entities" : { "properties": { "name": { "type": "string", "boost": 2.0, "analyzer": "snowball" },

我已经用这个JSON创建了我的索引和映射

// 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" }
            }
        }
    }
{
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "should": [
            {
              "has_child": {
                "type": "products",
                "query": {
                  "query_string": {
                    "query": "tab"
                  }
                }
              }
            },
            {
              "query_string": {
                "query": "tablet"
              }
            }
          ]
        }
      },
      "filter": {
        "or": [
          {
            "term": {
              "itype": "entities"
            }
          }
        ]
      }
    }
  }
}
现在,我已经使用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

// 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" }
            }
        }
    }
{
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "should": [
            {
              "has_child": {
                "type": "products",
                "query": {
                  "query_string": {
                    "query": "tab"
                  }
                }
              }
            },
            {
              "query_string": {
                "query": "tablet"
              }
            }
          ]
        }
      },
      "filter": {
        "or": [
          {
            "term": {
              "itype": "entities"
            }
          }
        ]
      }
    }
  }
}
我没有得到结果,但我像这样更改了查询字符串,然后得到了结果

      "query_string": {
        "default_field" : "description"
        "query": "tablet"
      }
能否请您确认我,我们是否应该在查询字符串中提及默认_字段以获得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
当查询中未指定
“默认\u字段”
时,elasticsearch使用特殊的
字段执行搜索。由于您没有更改默认分析器,也没有为映射中的
\u all
字段指定分析器,因此使用analyzer对
\u all
字段执行搜索