我正在用elasticsearch和php實現我的腳。我有產品名稱,如9×4卡車司機,19×40汽車座椅,等等等等如果沒有空格,elasticsearch搜索不起作用
我正在尋找這樣的
$params = [
'index' => 'myindex',
'type' => 'products',
'body' => [
'query' => [
'match' => [
'name' => '9 x12'
]
],
]
];
我的索引,以便該返回自己的產品,在他們的名字有9×12。但是當我嘗試通過'name'=>'9 x12'來搜索9x12時,沒有任何東西會被返回。我錯過了什麼。由於
EDITED 我用它來填充指數
PUT /myindex
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 0,
"analysis": {
"analyzer": {
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"doc": {
"properties": {
"text_field": {
"type": "string",
"analyzer": "whitespace_analyzer"
}
}
}
}
}
我也曾嘗試下面的設置,但他們沒有工作,要麼
PUT /myindex
{
"settings":{
"analysis": {
"analyzer": {
"lowercasespaceanalyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"products" : {
"properties" : {
"title" : { "type" : "string", "analyzer" : "lowercasespaceanalyzer", "tokenizer": "lowercase", "search_analyzer":"whitespace", "filter": [
"lowercase"
] }
}
}
}
}
更新::我的電流測繪
我用api調用獲取當前映射。不知道這是否會幫助,但在這裏它是
{
clipboards: {
mappings: {
products: {
properties: {
product: {
properties: {
bottomleft_png: {},
bottomright_png: {},
cost: {},
date_added: {},
date_available: {},
date_modified: {},
description: {},
ean: {},
height: {},
image: {},
isbn: {},
jan: {},
length: {},
length_class_id: {},
location: {},
manufacturer_id: {},
minimum: {},
model: {},
mpn: {},
options: {},
points: {},
price: {},
product_gallery: {},
product_id: {},
quantity: {},
shipping: {},
sku: {},
sort_order: {},
status: {},
stock_status_id: {},
subtract: {},
tax_class_id: {},
topleft_png: {},
topright_png: {},
upc: {},
viewed: {},
weight: {},
weight_class_id: {},
width: {}
}
}
}
}
}
}
}
樣品文件
"_index": "clipboards",
"_type": "products",
"_id": "100",
"_score": 1,
"_source": {
"product": {
"product_id": "100",
"model": "9043",
"sku": "",
"upc": "",
"ean": "",
"jan": "",
"isbn": "",
"mpn": "",
"location": "",
"quantity": "67",
"stock_status_id": "8",
"image": "catalog/Clipboards/Clipboard_accessories/Bands/ISO-bands/iso-clipboard-bands-a29135.jpg",
"manufacturer_id": "13",
"shipping": "1",
"name": "9x4 truck"
"price": "4.9500",
"points": "360",
"tax_class_id": "9",
"date_available": "2013-09-08",
"weight": "0.05000000",
"weight_class_id": "5",
"length": "0.00000000",
"width": "0.00000000",
"height": "0.00000000",
"length_class_id": "3",
"subtract": "1",
"minimum": "1",
"sort_order": "1",
"status": "1",
"viewed": "585",
"date_added": "2015-04-07 02:04:21",
"date_modified": "2015-11-25 12:42:17",
"topleft_png": "",
"options": [
{
"product_option_value_id": "31",
"product_option_id": "232",
"product_id": "100",
"option_id": "17",
"option_value_id": "64",
"quantity": "100",
"subtract": "1",
"price": "0.0000",
"price_prefix": "+",
"points": "0",
"points_prefix": "+",
"weight": "0.00000000",
"weight_prefix": "+",
"option_name": "Black",
"main_option_heading_sort_order": "1",
"main_option_heading": "ISO Band Color"
},
{
"product_option_value_id": "32",
"product_option_id": "232",
"product_id": "100",
"option_id": "17",
"option_value_id": "65",
"quantity": "100",
"subtract": "1",
"price": "0.0000",
"price_prefix": "+",
"points": "0",
"points_prefix": "+",
"weight": "0.00000000",
"weight_prefix": "+",
"option_name": "Pink",
"main_option_heading_sort_order": "2",
"main_option_heading": "ISO Band Color"
},
{
"product_option_value_id": "33",
"product_option_id": "232",
"product_id": "100",
"option_id": "17",
"option_value_id": "66",
"quantity": "100",
"subtract": "1",
"price": "0.0000",
"price_prefix": "+",
"points": "0",
"points_prefix": "+",
"weight": "0.00000000",
"weight_prefix": "+",
"option_name": "Clear",
"main_option_heading_sort_order": "3",
"main_option_heading": "ISO Band Color"
}
],
"product_gallery": []
}
}
}
也映射看起來不正確,你能不能跑捲曲-XGET'的'localhost:9200/your_index/your_type/_mapping''和發佈的,輸出? – ChintanShah25
如果您更清楚地陳述您的要求,哪些文件應該符合'9 x12',這將有所幫助? – ChintanShah25
不知道你的文件是什麼意思?我需要在名稱字段和產品類型上進行搜索! – Autolycus