弹性搜索同义词如何映射_all属性

时间:2018-12-14 09:41:09

标签: elasticsearch elastic-stack elasticsearch-5

我为索引创建了新的同义词,我正在使用查询字符串,但无法按弹性文档使用_all已默认启用。但是当我使用特定属性进行映射时,我们正在使用查询字符串和查询来获取数据

1)创建同义词和索引

PUT /laptops/
{
    "settings": {
        "index" : {
            "analysis" : {
                "filter" : {
                    "synonym_filter" : {
                        "type" : "synonym",
                        "synonyms" : [
                            "laptop, notebook"
                        ]
                    }
                },
                "analyzer" : {
                    "synonym_analyzer" : {
                        "tokenizer" : "standard",
                        "filter" : ["lowercase", "synonym_filter"] 
                    }
                },
           "mappings": {
          "doc": {
      "_all": {
        "enabled": true,
        "analyzer": "synonym_analyzer" 
      }
            }
        }
    } 
}
}
}

2将数据添加到索引

PUT /laptops/doc/1?pretty&pretty
{
  "title": "Laptop X1 i7 8gb RAM "
}

PUT /laptops/doc/2?pretty&pretty
{
  "title": "Laptop X2 i5 4gb RAM "
}
PUT /laptops/doc/3?pretty&pretty
{
  "title": "Laptop X3 i3 2gb RAM "
}
PUT /laptops/doc/4?pretty&pretty
{
  "title": "Laptop Z1 i7 6gb RAM "
}

3我正在使用查询字符串来获取数据

GET  /laptops/_search?pretty
{
  "query": {
    "query_string": {
      "query": "notebook"
    }
  }
}

0 个答案:

没有答案