Kibana字段不可搜索:test_produit索引仅nom字段可搜索求解答
nom Field Is Searchable in Your test_produit Index Hey there! This is a super common issue with Elasticsearch, and it almost always ties back to how your index's mapping is set up or how you're querying the fields. Let's break down the most likely causes and how to diagnose them:
1. Only nom is mapped as a text type
Elasticsearch only supports full-text search on fields marked as text—this type gets analyzed (split into searchable tokens) to enable keyword matches. Other field types like keyword, integer, date, or boolean don’t support full-text search by default; you can only query them with exact matches or range filters.
For example, if your index mapping looks like this:
{ "mappings": { "properties": { "nom": { "type": "text" }, "description": { "type": "keyword" }, "prix": { "type": "integer" } } } }
nomwill work withmatchormulti_matchqueries (full-text search)descriptioncan only be found with exacttermqueries (case-sensitive, no partial matches)prixrequires numerical queries (like ranges or exact values)
To check your current mapping, run this command:
GET test_produit/_mapping
2. Dynamic mapping is disabled or misconfigured
If you turned off dynamic mapping (dynamic: false) in your index settings, any fields not explicitly defined in your mapping won’t be indexed at all. That means even if you send documents with other fields, Elasticsearch ignores them—so they can’t be searched.
Here’s what that misconfiguration might look like:
{ "mappings": { "dynamic": false, "properties": { "nom": { "type": "text" } } } }
In this case, only nom gets indexed; all other fields are discarded.
3. Fields are empty or weren’t properly indexed
Sometimes the issue isn’t the mapping—it’s the data. Double-check that your documents actually have valid values in the non-searchable fields. Run a search to fetch a sample document:
GET test_produit/_search
Or look up a specific document by ID:
GET test_produit/_doc/your-document-id
If the fields are null, empty strings, or formatted incorrectly (like a string that should be a number), Elasticsearch might not index them as expected.
4. You’re using the wrong query type
Even if a field is indexed, using the wrong query will fail to return results. For example:
- Use
matchormatch_phrasefortextfields (full-text search) - Use
termortermsforkeyword, numerical, or boolean fields (exact matches) - Use
rangequeries for dates or numbers
If you try to use a match query on a keyword field, it won’t work unless the query text exactly matches the field value (including case).
To fix this, start by checking your index mapping to confirm field types. If you need full-text search on other fields, update the mapping to set them as text (you’ll likely need to reindex your data if the index already exists).
内容的提问来源于stack exchange,提问作者tomak

