Elasticsearch - 过滤器不起作用

时间:2016-02-16 16:16:06

标签: elasticsearch

我正在尝试构建一个查询以返回某个类型的所有产品:

curl -XPOST 'http://172.17.0.2:9200/products/_search?pretty' -d '
{
"query" : {
    "filtered" : { 
        "query" : {
            "match_all" : {} 
        },
        "filter" : {
            "term" : { 
                "genre" : "Feminino"
            }
        }
    }
}
}'

但结果是零产品。查询不返回任何内容。 如果我删除了过滤器分配,则查询有效:

curl -XPOST 'http://172.17.0.2:9200/products/_search?pretty' -d '
{
"query" : {
    "filtered" : { 
        "query" : {
            "match_all" : {} 
        }
    }
}
}'

我的索引设置为:

curl -s http://172.17.0.2:9200/products/_settings |python -m json.tool
{
"products": {
    "settings": {
        "index": {
            "creation_date": "1455635219340",
            "number_of_replicas": "1",
            "number_of_shards": "5",
            "products": {
                "mappings": {
                    "properties": {
                        "avaliability": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "best_seller": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "brand": {
                            "index": "not_analyzed",
                            "type": "double"
                        },
                        "brand_lenses": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "category": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "color": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "color_arm": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "color_lense": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "description": {
                            "type": "string"
                        },
                        "duration": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "final_price": {
                            "index": "not_analyzed",
                            "type": "double"
                        },
                        "format": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "front_image": {
                            "type": "string"
                        },
                        "genre": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "installment_amount": {
                            "index": "not_analyzed",
                            "type": "double"
                        },
                        "installment_times": {
                            "index": "not_analyzed",
                            "type": "integer"
                        },
                        "lenses_type": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "link": {
                            "type": "string"
                        },
                        "manufacturer": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "material": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "model": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "name": {
                            "type": "string"
                        },
                        "new": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "pathology": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "price": {
                            "index": "not_analyzed",
                            "type": "double"
                        },
                        "price_in_cash": {
                            "index": "not_analyzed",
                            "type": "double"
                        },
                        "qty": {
                            "index": "not_analyzed",
                            "type": "integer"
                        },
                        "side_image": {
                            "type": "string"
                        },
                        "sku": {
                            "type": "string"
                        },
                        "toast": {
                            "index": "not_analyzed",
                            "type": "string"
                        },
                        "type": {
                            "index": "not_analyzed",
                            "type": "string"
                        }
                    }
                }
            },
            "uuid": "jxYCUwUGSHW3Rj-A5Q0Tkg",
            "version": {
                "created": "2020099"
            }
        }
    }
}

我的查询或索引中是否有错误?

编辑:没有过滤器的搜索输出:

curl -s -XPOST 'http://172.17.0.2:9200/products/_search?pretty&size=1' -d '
{
 "query" : {
     "filtered" : { 
         "query" : {
             "match_all" : {} 
         }
     }
 }
}' | python -m json.tool
{
"_shards": {
    "failed": 0,
    "successful": 5,
    "total": 5
},
"hits": {
    "hits": [
        {
            "_id": "30-2024-MMBQ1090_C4",
            "_index": "products",
            "_score": 1.0,
            "_source": {
                "avaliability": "[out of stock]",
                "best_seller": "",
                "brand": "1.8.1",
                "category": "\u00d3culos de Grau",
                "color": "Marrom",
                "color_arm": "Marrom",
                "color_lense": "",
                "description": "Esse charmoso \u00f3culos possui a super tend\u00eancia cor marsala, um vinho mais fechado pro marrom, que transmite eleg\u00e2ncia imediata. Al\u00e9m disso, na lateral da sua haste ele mostra um detalhe met\u00e1lico incr\u00edvel, que enche esse modelo de personalidade. Seu formato retangular d\u00e1 o toque final de estilo contempor\u00e2neo. Muito belo! preencher",
                "final_price": 197.0,
                "format": "Retangular",
                "front_image": "https://media.eotica.com.br/catalog/product/cache/1/small_image/266x120/9df78eab33525d08d6e5fb8d27136e95/o/c/oculos-181-mmbq1090p-c4-1-rn.jpg",
                "genre": [
                    "Feminino",
                    "Masculino"
                ],
                "id": "30-2024-MMBQ1090_C4",
                "installment_amount": 65.67,
                "installment_times": "3",
                "lenses_type": "",
                "link": "https://www.eotica.com.br/oculos-de-grau-181-jacob-mmbq-1090-marrom-c4.html",
                "material": "N\u00e3o Metal",
                "model": "MMBQ1090 ",
                "name": "181 Jacob MMBQ1090 - Marrom - C4 - \u00d3culos de Grau",
                "new": "",
                "price": 197.0,
                "price_in_cash": 187.15,
                "qty": 0,
                "side_image": "https://media.eotica.com.br/catalog/product/o/c/oculos-181-mmbq1090p-c4-1-rn.jpg",
                "sku": "30-2024-MMBQ1090_C4",
                "toast": "0"
            },
            "_type": "product"
        }
    ],
    "max_score": 1.0,
    "total": 10416
},
"timed_out": false,
"took": 1
}

1 个答案:

答案 0 :(得分:0)

解决。

问题是标准分析仪。

使用带有标准令牌过滤器的标准令牌器,小写令牌过滤器和停止令牌过滤器构建标准型分析器。

https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html

所以,查询:

curl -XPOST 'http://172.17.0.2:9200/products/_search?pretty' -d '
{"query" : {
"filtered" : { 
    "query" : {
        "match_all" : {} 
    },
    "filter" : {
        "term" : { 
            "genre" : "feminino"
        }
    }
}

}     }'

工作得非常好。