在进行分面时动态字段被标记化

时间:2016-06-27 06:14:03

标签: php elasticsearch lucene

我有一个名为 * _ value 的动态字段。字段 os_value ,其中包含 android 5,android 5.1,android 6 等值。

在字段 os_value 上进行分面时,值会被标记为 android 计为 3 5 1 5.1 1 6 1

索引的映射如下。

{
"test_prod": {
    "aliases": {},
    "mappings": {
        "products": {
            "properties": {
                "*_capacity": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "*_value": {
                    "type": "string",
                    "index": "not_analyzed",
                    "include_in_all": false
                },
                "*_rating": {
                    "type": "double"
                },
                "*_value": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "attribute_set": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "availability": {
                    "type": "integer"
                },
                "battery_capacity": {
                    "type": "string"
                },
                "battery_capacity_value": {
                    "type": "long"
                },
                "battery_life_rating": {
                    "type": "long"
                },
                "brand": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "brand_label": {
                    "type": "string"
                },
                "camera_rating": {
                    "type": "long"
                },
                "capacity": {
                    "type": "long"
                },
                "category": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "class": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "color": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "configuration": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "connectivity": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "created_at": {
                    "type": "integer"
                },
                "description": {
                    "type": "string"
                },
                "design_rating": {
                    "type": "long"
                },
                "designed_for": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "discount": {
                    "type": "double"
                },
                "display_rating": {
                    "type": "long"
                },
                "features": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "front_camera_resolution_range": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "front_camera_resolution_value": {
                    "type": "long"
                },
                "graphics_memory_capacity": {
                    "type": "string"
                },
                "hard_disk_capacity": {
                    "type": "string"
                },
                "headset_design": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "headset_type": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "id": {
                    "type": "integer"
                },
                "image_big": {
                    "type": "string",
                    "index": "not_analyzed",
                    "include_in_all": false
                },
                "image_slider": {
                    "type": "string",
                    "index": "not_analyzed",
                    "include_in_all": false
                },
                "image_thumb": {
                    "type": "string",
                    "index": "not_analyzed",
                    "include_in_all": false
                },
                "interface": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "internal_storage": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "is_default": {
                    "type": "integer"
                },
                "is_exclusive": {
                    "type": "integer"
                },
                "key": {
                    "type": "string"
                },
                "last_update": {
                    "type": "date",
                    "format": "Y-m-d H:m:s"
                },
                "material": {
                    "type": "string"
                },
                "model": {
                    "type": "string"
                },
                "mrp": {
                    "type": "double"
                },
                "ndtv_rating": {
                    "type": "long"
                },
                "network_type": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "os": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "os_label": {
                    "type": "string"
                },
                "performance_rating": {
                    "type": "long"
                },
                "popularity": {
                    "type": "integer"
                },
                "processor_core": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "processor_name": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "product_id": {
                    "type": "long"
                },
                "product_specs": {
                    "type": "string"
                },
                "promo_label": {
                    "type": "string"
                },
                "pros_cons": {
                    "type": "string"
                },
                "ram_range": {
                    "type": "string"
                },
                "ram_value": {
                    "type": "long"
                },
                "rear_camera_resolution_range": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "rear_camera_resolution_value": {
                    "type": "long"
                },
                "register_mode": {
                    "type": "string"
                },
                "related_sku": {
                    "type": "string"
                },
                "release_priority": {
                    "type": "long"
                },
                "review_url": {
                    "type": "string"
                },
                "screen_size": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "screen_size_value": {
                    "type": "double"
                },
                "selling_price": {
                    "type": "double"
                },
                "shop_url": {
                    "type": "string"
                },
                "sim3g": {
                    "type": "long"
                },
                "sim4g": {
                    "type": "long"
                },
                "sim_type": {
                    "type": "string"
                },
                "sku": {
                    "type": "string"
                },
                "slug": {
                    "type": "string"
                },
                "software_rating": {
                    "type": "long"
                },
                "source": {
                    "type": "string"
                },
                "ssd_capacity": {
                    "type": "string"
                },
                "stock": {
                    "type": "string"
                },
                "subtitle": {
                    "type": "string"
                },
                "system_memory": {
                    "type": "string"
                },
                "tags": {
                    "type": "string"
                },
                "theme": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "title": {
                    "type": "string"
                },
                "title_raw": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "title_suggest": {
                    "type": "string",
                    "analyzer": "autocomplete_analyzer",
                    "search_analyzer": "standard"
                },
                "type": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "value_for_money_rating": {
                    "type": "long"
                },
                "variant_id": {
                    "type": "integer"
                },
                "voice_calling": {
                    "type": "integer"
                },
                "wifi": {
                    "type": "integer"
                },
                "wired_or_wireless": {
                    "type": "string",
                    "index": "not_analyzed"
                }
            }
        }
    },
    "settings": {
        "index": {
            "creation_date": "1467010796904",
            "analysis": {
                "filter": {
                    "autocomplete_filter": {
                        "type": "edge_ngram",
                        "min_gram": "1",
                        "max_gram": "20"
                    }
                },
                "analyzer": {
                    "autocomplete_analyzer": {
                        "filter": ["lowercase", "autocomplete_filter"],
                        "type": "custom",
                        "tokenizer": "standard"
                    }
                }
            },
            "number_of_shards": "5",
            "number_of_replicas": "1",
            "uuid": "BJbw5tD-assad",
            "version": {
                "created": "2030399"
            }
        }
    },
    "warmers": {}
}

}

此值也会在刻面时转换为小写。我做错了吗? 。请帮忙。

1 个答案:

答案 0 :(得分:0)

好的,我知道你正在努力实现的目标。你真正需要的是snippets。您需要删除索引并重新创建它:

POST test_prod
{
  "mappings": {
    "products": {
      "dynamic_templates": [
        {
          "capacities": {
            "match_mapping_type": "string",
            "match": "*_capacity",
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        {
          "values": {
            "match_mapping_type": "string",
            "match": "*_value",
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        {
          "ratings": {
            "match": "*_rating",
            "mapping": {
              "type": "double"
            }
          }
        }
      ],
      "properties": {
        "attribute_set": {
          "type": "string",
          "index": "not_analyzed"
        },
        "availability": {
          "type": "integer"
        },
        "battery_capacity": {
          "type": "string"
        },
        "battery_capacity_value": {
          "type": "long"
        },
        "battery_life_rating": {
          "type": "long"
        },
        "brand": {
          "type": "string",
          "index": "not_analyzed"
        },
        "brand_label": {
          "type": "string"
        },
        "camera_rating": {
          "type": "long"
        },
        "capacity": {
          "type": "long"
        },
        "category": {
          "type": "string",
          "index": "not_analyzed"
        },
        "class": {
          "type": "string",
          "index": "not_analyzed"
        },
        "color": {
          "type": "string",
          "index": "not_analyzed"
        },
        "configuration": {
          "type": "string",
          "index": "not_analyzed"
        },
        "connectivity": {
          "type": "string",
          "index": "not_analyzed"
        },
        "created_at": {
          "type": "integer"
        },
        "description": {
          "type": "string"
        },
        "design_rating": {
          "type": "long"
        },
        "designed_for": {
          "type": "string",
          "index": "not_analyzed"
        },
        "discount": {
          "type": "double"
        },
        "display_rating": {
          "type": "long"
        },
        "features": {
          "type": "string",
          "index": "not_analyzed"
        },
        "front_camera_resolution_range": {
          "type": "string",
          "index": "not_analyzed"
        },
        "front_camera_resolution_value": {
          "type": "long"
        },
        "graphics_memory_capacity": {
          "type": "string"
        },
        "hard_disk_capacity": {
          "type": "string"
        },
        "headset_design": {
          "type": "string",
          "index": "not_analyzed"
        },
        "headset_type": {
          "type": "string",
          "index": "not_analyzed"
        },
        "id": {
          "type": "integer"
        },
        "image_big": {
          "type": "string",
          "index": "not_analyzed",
          "include_in_all": false
        },
        "image_slider": {
          "type": "string",
          "index": "not_analyzed",
          "include_in_all": false
        },
        "image_thumb": {
          "type": "string",
          "index": "not_analyzed",
          "include_in_all": false
        },
        "interface": {
          "type": "string",
          "index": "not_analyzed"
        },
        "internal_storage": {
          "type": "string",
          "index": "not_analyzed"
        },
        "is_default": {
          "type": "integer"
        },
        "is_exclusive": {
          "type": "integer"
        },
        "key": {
          "type": "string"
        },
        "last_update": {
          "type": "date",
          "format": "Y-m-d H:m:s"
        },
        "material": {
          "type": "string"
        },
        "model": {
          "type": "string"
        },
        "mrp": {
          "type": "double"
        },
        "ndtv_rating": {
          "type": "long"
        },
        "network_type": {
          "type": "string",
          "index": "not_analyzed"
        },
        "os": {
          "type": "string",
          "index": "not_analyzed"
        },
        "os_label": {
          "type": "string"
        },
        "performance_rating": {
          "type": "long"
        },
        "popularity": {
          "type": "integer"
        },
        "processor_core": {
          "type": "string",
          "index": "not_analyzed"
        },
        "processor_name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "product_id": {
          "type": "long"
        },
        "product_specs": {
          "type": "string"
        },
        "promo_label": {
          "type": "string"
        },
        "pros_cons": {
          "type": "string"
        },
        "ram_range": {
          "type": "string"
        },
        "ram_value": {
          "type": "long"
        },
        "rear_camera_resolution_range": {
          "type": "string",
          "index": "not_analyzed"
        },
        "rear_camera_resolution_value": {
          "type": "long"
        },
        "register_mode": {
          "type": "string"
        },
        "related_sku": {
          "type": "string"
        },
        "release_priority": {
          "type": "long"
        },
        "review_url": {
          "type": "string"
        },
        "screen_size": {
          "type": "string",
          "index": "not_analyzed"
        },
        "screen_size_value": {
          "type": "double"
        },
        "selling_price": {
          "type": "double"
        },
        "shop_url": {
          "type": "string"
        },
        "sim3g": {
          "type": "long"
        },
        "sim4g": {
          "type": "long"
        },
        "sim_type": {
          "type": "string"
        },
        "sku": {
          "type": "string"
        },
        "slug": {
          "type": "string"
        },
        "software_rating": {
          "type": "long"
        },
        "source": {
          "type": "string"
        },
        "ssd_capacity": {
          "type": "string"
        },
        "stock": {
          "type": "string"
        },
        "subtitle": {
          "type": "string"
        },
        "system_memory": {
          "type": "string"
        },
        "tags": {
          "type": "string"
        },
        "theme": {
          "type": "string",
          "index": "not_analyzed"
        },
        "title": {
          "type": "string"
        },
        "title_raw": {
          "type": "string",
          "index": "not_analyzed"
        },
        "title_suggest": {
          "type": "string",
          "analyzer": "autocomplete_analyzer",
          "search_analyzer": "standard"
        },
        "type": {
          "type": "string",
          "index": "not_analyzed"
        },
        "value_for_money_rating": {
          "type": "long"
        },
        "variant_id": {
          "type": "integer"
        },
        "voice_calling": {
          "type": "integer"
        },
        "wifi": {
          "type": "integer"
        },
        "wired_or_wireless": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  },
  "settings": {
    "index": {
      "analysis": {
        "filter": {
          "autocomplete_filter": {
            "type": "edge_ngram",
            "min_gram": "1",
            "max_gram": "20"
          }
        },
        "analyzer": {
          "autocomplete_analyzer": {
            "filter": [
              "lowercase",
              "autocomplete_filter"
            ],
            "type": "custom",
            "tokenizer": "standard"
          }
        }
      },
      "number_of_shards": "5",
      "number_of_replicas": "1"
    }
  }
}