hi Team,
below is my query for searching
http://localhost:9200/news//_search { "query": { "bool": { "must": [{ "multi_match": { "query": "T&L" , "fields": [ "stkno", "tag" ,"content" ,"htext" ] ,"operator": "and"} }] } }, "from": 0, "size": 100, "sort": [ { "CDate": { "order": "desc" } } ] }
result can't get 'T&L', it will show result not related.how to get & also as value?
thanks and best regards
Sharon
val
(Val Crettaz)
January 18, 2018, 4:17am
2
Can you show the mapping you get from running the command below?
curl -XGET http://localhost:9200/news
val
(Val Crettaz)
January 18, 2018, 4:29am
4
That's what I feared, your fields are all string
, i.e. they are analyzed and thus the ampersand character is discarded at indexing time.
You need to either change the field type of those fields to being not_analyzed
strings, i.e.
"stkno": {
"type": "string",
"index": "not_analyzed"
},
or add a not_analyzed
sub-field.
"stkno": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
In both cases, you need to reindex your data.
Let us know
val:
"index": "not_analyzed"
what is the query for add index?
is it like this
PUT /news/trkd/_mapping/
{
"properties" : {
"tag" : {
"type" : "string",
"index": "not_analyzed"
}
}
}
need to delete the mapping first just create this mapping?
val
(Val Crettaz)
January 18, 2018, 4:36am
6
Yes, delete your index, modify your mapping accordingly and recreate the index with the new mapping. Then reindex your data and try your query again.
we can't create new mapping with current index?
when delete the index, no mapping found and how to create the mapping?
i have doing at reindex side, when reindex back to news, the mapping will same as before without that not-analysed
val
(Val Crettaz)
January 18, 2018, 7:38am
8
//1. delete the index
DELETE news
//2 . Create the new index with the new mapping
PUT news
{
"mappings": {
"trkd": {
"properties": {
...your fields go here...
}
}
}
}
//3. Reindex your data
...
// 4. search again
POST /news/_search
{...}
after done, it can be find, and total hits also less than before
but some index without T&L, also show out. Why?
val
(Val Crettaz)
January 18, 2018, 9:11am
10
Can you show the query you're sending and a document that is returned from your query but shouldn't?
this is query
http://localhost:9200/news//_search { "query": { "bool": { "must": [{ "multi_match": { "query": "E&O" , "fields": [ "stkno", "tag" ,"content" ,"htext" ] ,"operator": "and"} }] } }, "from": 0, "size": 500, "sort": [ { "CDate": { "order": "desc" } } ] }
result
val
(Val Crettaz)
January 18, 2018, 9:25am
13
Oh I see, since you've taken the second approach, you need to change your query to use the .raw
sub-fields instead, that should do the trick.
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "E&O",
"fields": [
"stkno.raw",
"tag.raw",
"content.raw",
"htext.raw"
],
"operator": "and"
}
}
]
}
},
"from": 0,
"size": 500,
"sort": [
{
"CDate": {
"order": "desc"
}
}
]
}
"stkno": {
"type": "string",
"index": "not_analyzed"
},
if i using this, mean i now need do stkno.raw right?
cause stkno.raw i need special handle during java coding.
val
(Val Crettaz)
January 18, 2018, 9:34am
15
That's correct. Your query simply needs to use the field that is not_analyzed
. So if you go with option 1, then your query stays the same, if you go with option 2, then you need to use the .raw
fields
i can get the result after i use first option.
if the value without this special character, it is whether can't find?
{ "query": { "bool": { "must": [{ "multi_match": { "query": "Malaysia" , "fields": [ "stkno", "tag" ,"content" ,"htext" ] ,"operator": "and"} }] } }, "from": 0, "size": 500, "sort": [ { "CDate": { "order": "desc" } } ] }
Actually Malaysia have this data in my index.
if i find like abc.N it can search.
is it by sentence it cant find if using "index": "not_analyzed"?
val
(Val Crettaz)
January 19, 2018, 6:00am
18
If you need both exact searches and full text search, then the first strategy I highlighted is the way to go. You can then do the exact matches on the *.raw
fields and the full text search on the normal fields.
system
(system)
Closed
February 16, 2018, 6:00am
19
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.