弹性搜索:单数和复数结果

时间:2012-12-20 11:54:57

标签: elasticsearch stemming

我们在映射中使用了minimal_english词干分析器。这是为了确保只有单数和复数是可搜索的而不是相似的单词。例如。在输入字词Test时,TestsTest 应该可搜索 - 但TesterTestersTesting 不应该。在尝试使用以下RESTful API进行搜索时,multi_field属性类型是可搜索的,但nested属性类型不是:

curl -X GET "http://10.113.124.136:9400/libtester/_search?pretty=true" -d '{
  "query": {
    "query_string": {
      "query": " DescriptionDescription ",
      "fields": [
        "abc"
      ]
    }
  }
}'

映射如下所示:

{
  "properties": {
    "abc": {
      "type": "multi_field",
      "fields": {
        "c_asset_id": {
          "type": "string",
          "index": "analyzed",
          "include_in_all": true,
          "analyzer": "basic_english"
        },
        "untouched": {
          "type": "string",
          "index": "analyzed",
          "include_in_all": false,
          "analyzer": "string_lowercase"
        }
      }
    },
    "xyz": {
      "type": "nested",
      "properties": {
        "c_viewpoint": {
          "type": "multi_field",
          "fields": {
            "c_viewpoint": {
              "type": "string",
              "index": "analyzed",
              "include_in_all": true,
              "analyzer": "basic_english"
            },
            "untouched": {
              "type": "string",
              "index": "analyzed",
              "include_in_all": false,
              "analyzer": "string_lowercase"
            }
          }
        }
      }
    },
    ...
  }
}

这是否与嵌套类型的映射有关 - xyz,它们不能从多字段类型的同一API中搜索到?

1 个答案:

答案 0 :(得分:1)

您可以搜索嵌套属性,只需要稍微不同的语法。您必须指定路径,然后显式使用您要搜索的每个属性的路径。

本教程有一个good overview of how nested documents work